Live data from Hacker News

Java: Missing Features

infoq.com

41–50 of 54 posts

Re: Java: Missing Features

#41
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…

> 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.

There's a free plugin that adds Lombok support to Intellij. You will be able to use getters/setters/builders etc. as if they were compiled.

Re: Java: Missing Features

#42
post #41

Earlier quoted context omitted.

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…

> 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. There's a free plugin that adds Lombok support to Intellij. You will be able to use getters/setters/builders etc. as if they were compiled.

Builders etc. work fine, it's the vals that are permanently underlined in red, even with the plug in. It compiles OK with vals, but still highlights it as an error in red in the editor.

Re: Java: Missing Features

#43
Moving from C# to Java 3 years ago was a painful experience in language expression.

However, IntelliJ, Java8 Streams, and Google Guava made the process tolerable.

I've grown to begrudgingly tolerate the weak Generics support, but the one thing absolutely still drives me insane is that I cannot have a method overload for a different generic parameter

i.e.

    public void do(List abcs);

    public void do(List defs);

FFS Java, come on. (Yes, I know, type erasure, it's still humiliating)

Re: Java: Missing Features

#44
post #3

Some of these, like reified generics, would be great, and it's sad it's too late to add them to the JVM. Some of these, like more expressive imports, seem pretty pointless given that we use IDE's. But some of these are quite un-Javaish. Structural typing would really go against the grain of the language, and i have a very hard time believing it would actually be useful. What method name is currently widely used with…

The visitor pattern essentially gives you pattern matching for your example. It can even give you destructuring pattern matching, if you wish. With a fixed hierarchy, each visit method handles one concrete case, and its signature can destructure fields and pass them individually. It's a hoop to jump through but not so bad.

Re: Java: Missing Features

#46

Earlier quoted context omitted.

So would this affect all flat memory allocation? Say if you wanted to allocate 100GB for a bloom filter, would you need to break it into chunks?

Yes, you'd need 6 arrays of 2147483648 longs (max int), plus one array of 536870912 longs, so a total of 7 arrays. Not that bad really.

Yes, I have code like that and its annoying and bug prone. Even if its a write one exercise :( Would be nice if could just avoid that exercise in bit shifting and anding.

Re: Java: Missing Features

#47
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…

Lombok's val is the only thing I don't use in the Lombok library.

Re: Java: Missing Features

#48
post #14

> The issue of primitive specialisation of generics is only tangentially related to type erasure, and run-time visible generics are actually much less useful than Java folk wisdom insists. Run-time visible generics are pretty important because it lets us avoid boxing everything. In .NET, they don't have this problem, and as a result primitive dictionaries are ~17x faster [0]. Java folk wisdom seems pretty accurate to…

Did you read any of the comments? I did and I am certainly not qualified enough to know if the 17x faster claim holds up at all.

I did now, and the only relevant retort I saw to this specific claim was that it is possible to work around it by using cern.colt.map.OpenIntDoubleHashMap (third party) instead of java.util.HashMap. So someone has worked around the problem by creating an implementation for a specific value type, but as the author explains, that comes with a big loss of genericity compared to the .NET solution.

Re: Java: Missing Features

#49
post #24

Things that would be good to add in Java are: - Collection and map literal. - Value type. - Multiple return values. - Destructure. - Pattern matching.

that multiple return values got me interested. I can see this exploding complexity/unreadability of the code at first glance. honest question - what would be real added value compared to dedicated wrapper type holding all you need for return?

It actually makes the code concise and clearer. e.g.

  (int, float, float) calcPosition(...) {
       ...
       return (type, x, y);
  }

  var (type, x, y) = calcPosition(...);
  if (type)
     move(x, y);
or

  var (int type, float x, float y) = calcPosition(...);
I would prefer the first case with automatic type inference.

Re: Java: Missing Features

#50
post #44
post #3

Some of these, like reified generics, would be great, and it's sad it's too late to add them to the JVM. Some of these, like more expressive imports, seem pretty pointless given that we use IDE's. But some of these are quite un-Javaish. Structural typing would really go against the grain of the language, and i have a very hard time believing it would actually be useful. What method name is currently widely used with…

The visitor pattern essentially gives you pattern matching for your example. It can even give you destructuring pattern matching, if you wish. With a fixed hierarchy, each visit method handles one concrete case, and its signature can destructure fields and pass them individually. It's a hoop to jump through but not so bad.

Very true, but you have to write it all by hand, so it's the usual tedious and error-prone boilerplate until IDEs learn to autogenerate it. It would be nice to have an automatic solution like you get with real ADTs.
Post reply on HN