Overview
This pull request updates the static initialization block in the AnsiPropertySource class. The goal is to leverage modern Java features for cleaner and more readable code.
Changes
- Replaced the verbose
ArrayListandCollections.unmodifiableListinitialization with the more conciseList.of()method available from Java 9 onwards. - This change reduces the code's verbosity, making it more readable and easier to maintain.
- The use of
List.of()ensures that the list is inherently immutable, aligning with best practices for handling static final lists.
Justification
- Readability: The original code used an
ArrayListfollowed by wrapping it withCollections.unmodifiableList. While this approach is valid, it's more verbose and less readable. The new approach usingList.of()is more straightforward and expressive. - Modern Practices: Since the project targets Java 11/17, it's beneficial to utilize the newer and more efficient Java features.
List.of()is a modern and concise way to initialize immutable lists, which is a common pattern in recent Java codebases. - Performance and Safety: The immutable list created by
List.of()is more performant and safer, as it prevents accidental modifications of the list, which is crucial for static final lists.
Conclusion
By adopting this change, the AnsiPropertySource class becomes more aligned with modern Java practices, enhancing code readability and maintainability while ensuring immutability and safety of the static list.