JDK 10 launched has added 70+ new APIs and Options in the Java library. Some important intensifications introduced are given below.
A new way orElseThrow() is accessible in java.util.Optional class is now a favourable alternative for get() way.
A new way copyOf() is accessible in List, Set and Map interfaces which can make new group instances from the present one. Collector class has new ways toUnmodifiableList(), toUnmodifiableSet(), and toUnmodifiableMap() to acquire components of a stream into an unmodifiable troupe.
A new flag is inaugurated jdk.disableLastUsageTracking which disables JRE's last utilization tracking for a processing VM.
The plain text written passwords accessible in the jmxremote.password files are now being overwritten with their SHA3-512 hash by the JMX agent.
A new option is accessible to the javadoc command as --add-stylesheet. This option hold up the use of multiple stylesheets in created documentation.
A new option is accessible to the Javadoc command as --overridden-methods=value. As many classes override inherited ways but do not interchange the definition. The --overridden-methods=value option permits to group these ways with any other inherited methods, rather than documenting them again individually.
A new inline tag, {@summary ...}, is accessible to define the text to be used as the sum up of the API explanation. By default, the sum up of an API description is concluded from the very first sentence.
The use of some of the new APIs in JAVA 10, will be shown in the given example.
import java.util.List; import java.util.stream.Collectors; public class Tester { public static void main(String[] args) { var ids = List.of(1, 2, 3, 4, 5); try { // get an unmodifiable list List<Integer> copyOfIds = List.copyOf(ids); copyOfIds.add(6); } catch(UnsupportedOperationException e){ System.out.println("Collection is not modifiable."); } try{ // get an unmodifiable list List<Integer> evenNumbers = ids.stream() .filter(i -> i % 2 == 0) .collect(Collectors.toUnmodifiableList());; evenNumbers.add(6); }catch(UnsupportedOperationException e){ System.out.println("Collection is not modifiable."); } } }
Output
Your outcome will look like this
Collection is not modifiable. Collection is not modifiable.