[HN Gopher] New Features in Java 14 ___________________________________________________________________ New Features in Java 14 Author : pjmlp Score : 33 points Date : 2020-03-03 19:00 UTC (4 hours ago) (HTM) web link (blogs.oracle.com) (TXT) w3m dump (blogs.oracle.com) | insertnickname wrote: | "Java 14 is scheduled for release on March 17" | | So it didn't quite arrive yet. | The_rationalist wrote: | Java is getting true pattern matching in version 15, what a time | to be alive! | dang wrote: | Related from a few weeks ago: | https://news.ycombinator.com/item?id=22237145 | rafaelvasco wrote: | "Helpful NullPointerExceptions": One of the biggest pain points | of Java, probably the biggest. Good that it's being finally | solved; | hyperpallium wrote: | It's just better error messages (where within expression, not | just which line). | [deleted] | cryptos wrote: | Java is quite far away from finally solving | NullPointerException issues. Kotlin, C# or TypeScript with | their compile time null checks solved it mostly. Common to | these three languages is that they need null to be | interoperable with older language versions (C#) or with related | languages (Java, JavaScript). Languages like Rust that don't | even know null (or nil as in Go), have finally solved the | problem. | rakoo wrote: | > Languages like Rust that don't even know null (or nil as in | Go), have finally solved the problem. | | I'm in no way a Rust expert, but I see a lot of code with | Optionals, something like match sth { | Some(v) => do_something None => nothing_to_do | } | | This looks awfully a lot like if (something | == null) { nothing_to_do } else { | do_something } | | It might look more pleasant, but it doesn't "solve" anything, | only shifts it in a different place. | | Go is in the middle, because structs have no null value, only | a zero value; the only thing that can be nil are pointers | which I personally feel should used as little as possible. | bcrosby95 wrote: | It solves it by making sure you handle it at compile time. | | In Java you tend not to know where or when null checks have | or will happen. So you tend to sprinkle null checks all | over your code just incase someone somewhere forgot to | check. | fidelramos wrote: | The key difference is that in your second example you can | just forget about the else branch, while in Rust you must | explicitly handle the None case, otherwise it won't | compile. | hawk_ wrote: | The difference is that the choice of Optional is deliberate | in the parts of code where None is a valid value. In java | you have no first class way to indicate that null isn't an | expected value for some variable and so type checker can't | block it. In rust type checker wont let None slip in | accidentally if you don't use Optional. | Sharlin wrote: | In Java you're passed a reference to an object. Might it be | null? _Can_ it be null? Who knows! Mostly you 're just | going to ignore the possibility and hope for the best. | | In Rust you're passed a reference to an object. Can it be | null? No, it simply can't! There does not exist a magic | "null" value for references. To represent the possible | absence of a value, you _explicitly_ encode it into the | type system by using `Option <T>`. | justinhj wrote: | Scala does a pretty good job too, with the help of build | plugins you can avoid null polution (which normally comes | from Java libraries) pretty well. | yayajacky wrote: | You hit it right on the nail. I love how the null type being | defined away from function signature in TS. It's not entirely | bug free but it gets pretty far! ___________________________________________________________________ (page generated 2020-03-03 23:00 UTC)