To maintain code quality, use the following modern Java patterns:
Local Type Inference
Use var for local variables when the type is clear from the context. Avoid it if the type is ambiguous.
var uploadFile = new File(UPLOAD_FILE_NAME);
var response = s3Client.getObject(...);
Collections
- Use
list.isEmpty() or !list.isEmpty() instead of checking list.size() == 0. - Use
List.of(...) and Map.of(...) for immutable collections instead of Collections.unmodifiableList(...). - Prefer Streams over explicit loops for transformations:
buckets.stream().map(Bucket::name).collect(Collectors.toSet())
Switch Expressions and Text Blocks
- Prefer switch expressions over
if-else chains when dealing with 3 or more branches. - Use text blocks for all multi-line strings.
var uploadFile = new File(UPLOAD_FILE_NAME);
var response = s3Client.getObject(...);
buckets.stream().map(Bucket::name).collect(Collectors.toSet())