|
switch (attributeName) { |
|
case SIZE -> { |
|
return size; |
|
} |
|
case OWNER -> { |
|
return owner; |
|
} |
|
case IS_DIRECTORY -> { |
|
return isDirectory; |
|
} |
|
case FILENAME -> { |
|
return filename; |
|
} |
|
} |
|
throw new IllegalArgumentException("invalid filter criteria type"); |
As -> is alread used in the switch block, it can be enhanced:
return switch (attributeName) {
case SIZE -> size;
case OWNER -> owner;
case IS_DIRECTORY -> isDirectory;
case FILENAME -> filename;
}
This is better as you can skip the unnecessary throw at the end, as the switch branch is exhaustive.
ood-interview/file_search/filesearch/filesystem/File.java
Lines 27 to 41 in bce98e5
As
->is alread used in theswitchblock, it can be enhanced:This is better as you can skip the unnecessary
throwat the end, as the switch branch is exhaustive.