4 ms·
Btw Kotlin solves that. You can write to non final variables inside lambdas.
by fidgewidge 4y ago
Btw Kotlin solves that. You can write to non final variables inside lambdas.
- vbezhenar 4y agoYep, Kotlin solves almost all pain points with Java and presents a good show-case which Java language developers should have followed IMO. Another examples of Java pain points solved in Kotlin which I could remember: top-level functions (which are actually bundled in some "standard" class name. Pretty much syntax sugar but very nice. Auto cast. Like you check variable with instanceof and after this check it's automatically casted to the target type. Java has some weird syntax for this but I don't see why this was necessary at all. More default imports. Why should I qualify java.util. it's pretty much standard. I'm not asking for every java.x package to be auto-imported, but commonly used packages should be. Class properties instead of getter/setter ceremony. Records are alternative approach but I don't find it useful yet. Nullability. Of course that's a hard question and adding nullability to existing type system looks like gargantuan task. What could be done is introduce some java.xxx annotation, let module projects to be not-null by default (so you don't need to create package-info.java in every package just to make it not-null) and make all nullability issues to be warnings from javac. Basically it's already exists but not standard and implementation quality varies. Reified generics. Basically it's a hidden Class<T> clazz argument passed automatically to the function. This is brilliant solution to type erasure problem and it should really have been adopted. I'd vote for all those features to be implemented in Java similarly to their Kotlin implementations.