Java 10 is finally released today. ~~ Maybe ~~ I think it will be available for download from here ~~. http://jdk.java.net/10/
Here is a summary of the new features in Java 10 that have JEP. Java 10 new feature summary --Qiita
However, there are quite a few changes other than those with JEP. Here, we will summarize the API and other changes that are likely to have an impact on changes other than JEP. Extraction from here. Click here for more information. 109 New Features In JDK 10 - Azul Systems, Inc.
Click here to download OpenJDK JDK 10 GA Release
Click here to download the Oracle JDK Java SE Development Kit 10- - Downloads
A getPid ()
method has been added to java.lang.management.RuntimeMXBean
to get the process ID.
import java.lang.management.ManagementFactory;
long pid = ManagementFactory.getRuntimeMXBean().getPid();
System.out.println(pid);
By the way, considering readability, it is better not to use var
in such a case.
It is hard to say that " var
is fine because you can see that it is long
by looking at the definition ofgetPid ()
."
Java 9 added Runtime.version ()
, but the Runtime.Version
class it takes has changed according to the new versioning.
feature ()
, ʻinterim (), ʻupdate ()
, patch ()
have been added, and major ()
, minor ()
, and security ()
have been deprecated. ..
Runtime.Version version = Runtime.version();
System.out.printf("%d.%d.%d.%d%n",
version.feature(), version.interim(), version.update(), version.patch());
In Java 9, the transferTo
method was added to java.io.InputStream
to allow transfer from ʻInputStream to ʻOutputStream
, but in Java 10 it was changed to java.io.Reader
. The transferTo
method has been added so that Reader
can also transfer to Writer
.
var sr = new StringReader("abc\ndef\n");
var sw = new StringWriter();
sr.transferTo(sw);
System.out.println(sw);
When using such a new
, you can see the type by looking at the right side, so I think that var
is fine.
The copyOf
method has been added to java.util.List
, java.util.Set
, and java.util.Map
to make copies of List
and so on.
var list = List.copyOf(List.of("aa", "bb", "cc"));
In the case of List
, it is an instance of java.util.ImmutableCollections $ ListN
, a private class that is also used in List.of
. If there are 0 to 2 elements, it will be an instance of a dedicated class such as List0.
If it was originally ʻImmutableCollections $ ListN`, as in this example, the given instance will be returned as is.
In JDK11, it seems to be unified to ListN.
http://hg.openjdk.java.net/jdk/jdk/rev/a14ede52a278
By the way, it is delicate whether copyOf
can be received by var
.
ʻOptional Other than that, ʻor ElseThrow (Supplier <Throwable>)
is already available.
Java 10 added ʻorElseThrow ()with no arguments. The
get () method throws an exception when ʻOptional
has no value. Therefore, at the beginning of writing this article, I thought that ʻor ElseThrow ()was unnecessary and omitted it, but in reality
get () is properly aware that an exception is thrown. I had to use it, and I realized that I should use ʻor ElseThrow ()
instead of get ()
.
Perhaps it seems that get ()
may become Deprecated in the future.
ToUnmodifiableList
, toUnmodifiableSet
, and toUnmodifiableMap
have been added to java.util.stream.Collectors
.
List<String> strs = Stream.of("aa", "bb")
.collect(Collectors.toUnmodifiableList());
It doesn't matter if there are duplicates in toUnmodifiableSet ()
, and one of them will be selected, but toUnmodifiableMap ()
will throw java.lang.IllegalStateException
if there are duplicate keys.
javax.ButtonModel#getGroup()
Swing also changed! !! !!
JavaDoc summaries can now be written in multiple lines using the {@Summary}
tag.
Until now, even if the JVM was running with Docker, the number of CPUs and memory etc. ignored the Docker settings and returned the number of CPUs and memory size of the platform, but from Java 10 it will read the Docker settings. I did. This had an effect when using Hadoop, Spark, etc. with Docker even if Java was not mainly used, so many people may be grateful.
There were switches to choose between the 32-bit and 64-bit versions of the JVM, but these switches are gone as only the 64-bit version is available.
It was deleted
If there is a file called * .conf
in ʻINCLUDEDIR, it will be included in
krb5.conf`.
XMLInputFactory # newFactory ()
was incorrectly labeled with @Deprecated
, but it has been removed.
There is also such a thing.
Recommended Posts