To run each example use: java --enable-preview --source 23 <FileName.java>
- 455 - Primitive Types in Patterns, instanceof, and switch (Preview)
- 466 - Class-File API (Second Preview)
- 467 - Markdown Documentation Comments
- 469 - Vector API (Eighth Incubator)
- 473 - Stream Gatherers (Second Preview)
- 474 - ZGC: Generational Mode by Default
- 476 - Module Import Declarations (Preview)
- 477 - Implicitly Declared Classes and Instance Main Methods (Third Preview)
- Primitive Types in Patterns, instance of and switch
- goal: "enhance pattern matching by allowing primitive type patterns in all pattern contexts"
- in JDK 21, primitive type patterns are allowed only as nested patterns in record pattern (e.g.:
v instanceof JsonNumber(double d)
) - this JEP will:
- extend pattern matching to allow primitive type patterns in all places (e.g.:
v instanceof JsonNumber(int i)
); - enhance
instanceof
andswitch
to support primitive type patterns as top level pattern - enhance
instanceof
to check the primitive type, beside the reference type checking, and also verify the primitive support value:- allowing to do an implicity cast during matching if, and only if, there is no loss of information (exact conversion)
- e.g.: if an
int
is to large for abyte
it will not be matched instanceof
will be used as safeguard for all conversions- in JLS §5.5 we can see the permited conversions
- enhance the
switch
to works with literals of all primitive types:- until JDK 21,
boolean
,float
,double
andlong
cannot be used as case value - switch will be exhaustive if it contains a unconditional type pattern
- an
int
is always along
, so a labelcase long l
will match any integer
- an
- switch and floating-points:
- if the switch's selector expression is a float then any case constants must be a floating-point literals
- floating-point literal in case labels is defined in terms of representation equivalence
- a label
case 1.0f
is considered the same ascase 0.99999999f
, will throw a duplicate label error
- a label
- until JDK 21,
- extend pattern matching to allow primitive type patterns in all places (e.g.:
- Stream Gatherers
- re-preview without change
- ZGC: Generational Mode by Default
- switch the default mode of ZGC to use generational mode
- deprecate the non-generational mode to be removed in the future
- reduce the maintenance cost of supporting two models
- default mode will act like using command-line args:
-XX:+UseZGC -XX:+ZGenerational
- non-generational can still be used with:
-XX:+UseZGC -XX:-ZGenerational
- Generational ZSG should be a better solution for most use cases
- Module Import Declarations
- allow import all packages exported by a module
- goal is simplify the learning and exploring of APIs without having to know its exactly package
- when importing a module, it will automatically import all its exported packages and its transitive dependencies
- syntax:
import module [Module Name]
import module java.sql
- ambiguous import:
- in case of two module exporting the same class name, we will have to import the class directly
-
import module java.base; // java.util.Date import module java.sql; // java.sql.Date import java.sql.Date;
- Implicitly Declared Classes and Instance Main Methods
- major change from JDK 21 and 22
- implicitly import methods from a new class
java.io.IO
- new class created for convenience IO
- provides methods:
print(Object)
,println(Object)
andreadln(String)
- this class uses return from
System.console()
to print and read from the default input and output streams
- implicitly class will automatically import all of the public top-level classes and interfaces from module
java.base