Live data from Hacker News

Java: Missing Features

infoq.com

21–30 of 54 posts

Re: Java: Missing Features

#21
post #2

What I would love to come over from C# is: * Auto-Properties - Get rid of all those ugle getters and setters cluttering up POJOs * Object and Collection Initialisers - https://msdn.microsoft.com/en-us/library/bb384062.aspx

If there's no logic in the getter and setters, just make the properties public.

That works until you want to add logic without breaking existing interfaces.

Re: Java: Missing Features

#22
post #21

Earlier quoted context omitted.

If there's no logic in the getter and setters, just make the properties public.

That works until you want to add logic without breaking existing interfaces.

Or until you need to use them in beans and the like.

Re: Java: Missing Features

#23
Apart from primitive specialization the biggest omission in my opinion is the lack of value types ("structs"). It's almost impossible to write code that is heap allocation free or allows reasoning about cache locality.

Re: Java: Missing Features

#24
Things that would be good to add in Java are:

- Collection and map literal.

- Value type.

- Multiple return values.

- Destructure.

- Pattern matching.

Re: Java: Missing Features

#25
post #21

Earlier quoted context omitted.

That works until you want to add logic without breaking existing interfaces.

Or until you need to use them in beans and the like.

Play!Framework 2 for Java is awesome in this matter. You write public members, but at compilation it transforms them into private members with getters and setters (if not final). It means if you write the setter, it overrides the default one.

Re: Java: Missing Features

#26
post #4

Earlier quoted context omitted.

might want to checkout lombok. https://projectlombok.org/

Just keep in mind that some of the features are a bit iffy. If you use their vals IntelliJ will syntax highlight it as an error in red for the simple reason that it's non-compliant with the Java language spec. Also, you'll usually need a new version on Lombok every time a new version of Java comes out, otherwise what used to compile with the previous java version will no longer compile. If you use the auto constructo…

True. I've seen multiple teams putting a lot of effort into removing Lombok from their codebases after all the trouble it caused.

Re: Java: Missing Features

#27
post #25

Earlier quoted context omitted.

Or until you need to use them in beans and the like.

Play!Framework 2 for Java is awesome in this matter. You write public members, but at compilation it transforms them into private members with getters and setters (if not final). It means if you write the setter, it overrides the default one.

Lombok does the same ;)

Re: Java: Missing Features

#28
Ok weird, as a scala programmer these aren't the main pain points when I go to a less powerful language. I miss monadic comprehension, implicit parameters/higher kinded types (for type classes) and inference the most.

Re: Java: Missing Features

#29

Apart from primitive specialization the biggest omission in my opinion is the lack of value types ("structs"). It's almost impossible to write code that is heap allocation free or allows reasoning about cache locality.

If you're familiar with the JVM's "escape analysis" then it is at least possible to write allocation-free code. But keeping a mental model of the JIT's optimizer in your head does not make for fun or easy programming. It's so much nicer to work with value types such as those found in C#.

Re: Java: Missing Features

#30

Apart from primitive specialization the biggest omission in my opinion is the lack of value types ("structs"). It's almost impossible to write code that is heap allocation free or allows reasoning about cache locality.

Just yesterday I've watched this: https://www.youtube.com/watch?v=88-szpeNfrU

Long story short: keep the traditional getters and setters but have just a byte[] field to store the object state. For example If you need just the date (without the time) you can store it in 2 bytes, say 7 and 8, and in getDate() method you do

    public Date getDate() {
         int day = bytes[8] * 256 + bytes[9]
         return new Date(day * MILLIS_PER_DAY);
    }
Some of the improvements are amazing
Post reply on HN