add support for Java 16
Closed this issue · 11 comments
What’s coming in Java 16?
https://www.infoworld.com/article/3569150/jdk-16-whats-coming-in-java-16.html#tk.rss_java
https://openjdk.java.net/projects/jdk/16/ as the official link, if somebody wants to read all jeps. From my understanding in December after rampdown phase 1 the feature list is more or less final and we only have to wait for jdt. I would expect records and instanceOf to reach the release state, and a preview for pattern matching (for more about pattern matching you can look at old languages like haskell)
The official Java 16 spec: https://docs.oracle.com/javase/specs/jls/se16/jls16.pdf
Going through the Java 16 specs, one of the possible changes, I identified is JEP 392: Packaging Tool.
jpackage tool is moved from jdk.incubator.jpackage to jdk.jpackage
Having a quick look at the release notes, it seems like there are only 2 new stable features and 1 new preview feature that require extensions in Spoon. IMO preview features are not worth supporting, though.
Stable features
- Records (JEP 395)
- We need a new
CtRecord
interface to model it - Note: This is pure syntactical sugar, it just generates a class with some stuff (e.g. getters for fields, an equals method, a toString, and some other stuff). Pretty much built-in Lombok.
- We need a new
- instanceof pattern matching (JEP 394)
- Allows an optional variable to cast to the checked type (if check is successful)
- E.g.
obj instanceof String s
instantiatess
to(String) obj
iffobj
is in fact aString
- May require a new
CtInstanceOf
interface that subtypesCtBinaryOperator
to make sense
Preview features
- Sealed types (preview 2, JEP 397)
- Classes and interfaces can restrict how they can be subtyped with the
sealed
modifier - IMO not worth supporting until stable
- Classes and interfaces can restrict how they can be subtyped with the
Can you give an estimation when java 16 support will be available? It would be really great to have this.
Can you give an estimation when java 16 support will be available? It would be really great to have this.
@jakobbraun Support for type patterns is essentially done in #4020, we just hit a minor snag on finalizing. It should be available in the next beta release this weekend, I think.
The other big thing is records, and for that I can't really say. No one has yet taken it upon themselves to implement that, so I can't give an ETA on it.
Note that sealed classes are slated to be stabilized in Java 17 (JEP-409)
#4020 has added instanceof pattern matching, next step to close this issue is record support.
I've created #4132 to discuss records.
Now that @MartinWitt's great #4134 is merged, it seems we can close this one.
WDYT?
The last needed step is updating the GitHub page, then all is done.