Further Java Modernization#1863
Conversation
kingthorin
commented
Jun 28, 2026
- collect(Collectors.toList()) ➡️ toList()
- Use List/Set/Map.of where immutables are okay
- Leverage Records
- Use updated instanceof form to reduce assignments/intermediate storage
- Leverage var + local variable type inference
- Use text blocks to avoid concatenation, etc.
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Types inferred at compile time; no runtime performance impact when var replaces an equivalent explicit type. Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1863 +/- ##
============================================
+ Coverage 92.48% 92.55% +0.06%
- Complexity 3561 3565 +4
============================================
Files 346 346
Lines 7050 7048 -2
Branches 684 685 +1
============================================
+ Hits 6520 6523 +3
+ Misses 366 364 -2
+ Partials 164 161 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| StringJoiner data = new StringJoiner(LINE_SEPARATOR); | ||
| for (IN in : input) { | ||
| for (var in : input) { |
There was a problem hiding this comment.
Either way it's dealt with at compile time not runtime.
| if (consumer == null) { | ||
| final Field<Object, ?>[] fields = schema.getFields(); | ||
| final Map<String, java.lang.reflect.Field> name2ClassField = Stream.of(clazz.getDeclaredFields()).collect( | ||
| var name2ClassField = Stream.of(clazz.getDeclaredFields()).collect( |
There was a problem hiding this comment.
before that the var was final, after that is not...
not sure we should make such change
There was a problem hiding this comment.
Good point, I'll check and revert those.
| public static String linesTrimTrailing(String textBlock) { | ||
| String result = lines(textBlock); | ||
| String sep = System.lineSeparator(); | ||
| return result.endsWith(sep) ? result.substring(0, result.length() - sep.length()) : result; |
There was a problem hiding this comment.
This might be dangerous especially for SQL containing \n inside values
INSERT INTO "MyTable" ("N\nu\nm\nb\ne\nr\n", "Password") VALUES (1, '5');There was a problem hiding this comment.
Okay, will revert.
|
@kingthorin While I generally like records, I must warn that after conversion a class to a recorder, all fields become publicly accessible. E.g. in class |
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
|
@asolntsev & @snuyanzin got your comments all addressed I believe. |