Apply "instanceof pattern matching" in AbstractRoutingDataSource

Closes gh-28011
This commit is contained in:
lijun695 2022-02-05 20:51:18 +08:00 committed by Sam Brannen
parent 9a0f691e86
commit 1e0e477833
1 changed files with 4 additions and 4 deletions

View File

@ -153,11 +153,11 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple
* @throws IllegalArgumentException in case of an unsupported value type * @throws IllegalArgumentException in case of an unsupported value type
*/ */
protected DataSource resolveSpecifiedDataSource(Object dataSource) throws IllegalArgumentException { protected DataSource resolveSpecifiedDataSource(Object dataSource) throws IllegalArgumentException {
if (dataSource instanceof DataSource) { if (dataSource instanceof DataSource result) {
return (DataSource) dataSource; return result;
} }
else if (dataSource instanceof String) { else if (dataSource instanceof String name) {
return this.dataSourceLookup.getDataSource((String) dataSource); return this.dataSourceLookup.getDataSource(name);
} }
else { else {
throw new IllegalArgumentException( throw new IllegalArgumentException(