java After the storm, it has been in existence for more than 30 years since its birth in 1995! There are a total of 1-10 10 large versions of Java. Of course, java10 is still in the stage of fixing bugs. It has not been officially released. The first official basic usable version is 3.20 in 2018. Let us look forward to it together! 🙂

The java10 schedule shown below:

Environmental Preparation

In order to quickly experience the java10, select [docker] ( environment is the best (do not install [docker] ( /tag/docker) Please refer to my other article for the environment: [Introduction to the world of docker] ( Take a look at the docker hub and see if there is any java10 tag.


As shown above, it really is!!)

Ok, then don’t talk nonsense, let’s run and see!

Running the Docker version of the Java10 container

Use the following command to run and enter the inside of the container:

The result is shown in the figure: (The docker run command will first download the openjdk image)

After entering the container, first use java -version to see the version:

You can see that it is indeed the java10 version, so let’s experience the new features one by one!

According to the openjdk official website description (

286: [Local-Variable Type Inference] (
296: [Consolidate the JDK Forest into a Single Repository] (
304: [Garbage-Collector Interface] (
307: [Parallel Full GC for G1] (
310: [Application Class-Data Sharing] (
312: [Thread-Local Handshakes] (
313: [Remove the Native-Header Generation Tool (javah)] (
314: [Additional Unicode Language-Tag Extensions] (
316: [Heap Allocation on Alternative Memory Devices] (
317: [Experimental Java-Based JIT Compiler] (
319: [Root Certificates] (
322: [Time-Based Release Versioning] (

Here we pick a few to see and experience it first!

286. Local variable type inference

Specific feature description:

Yes, you can now define your variables like this!

Finally, java can also define variables as simple as other dynamic languages. Before comparing java10, you can only write:

I don’t know how to practice fake! Try using jshell to knock two lines:

Look at the type of a, here use the instanceof keyword (although the basic type will report an error with this judgment, but it can also reflect its type)

Note the above error message found : int Description a has indeed been inferred to be an int type.

Look at the variable declaration of type String:

Looked good, but the actual identifier var is not a keyword!

The identifier var is not a keyword; instead it is a reserved type name or a context-sensitive keyword. This means that code that uses var as a variable, method, or package name will not be affected; code that uses var as a Class or interface name will be affected (but these names are rare in practice, since they violate usual naming conventions).

The meaning of translation is:

The identifier var is not a keyword, but a reserved type name or a context sensitive keyword. This means that code that uses var as a variable, method, or package name will not be affected; code that uses var as the class or interface name will be affected (but these names are rare in practice because they violate the usual naming conventions) ).

So, we declare that a variable can also be compiled normally:

But it is not possible to declare a class like this:

Usage restrictions

Of course, in addition to var there are some other restrictions on use, quickly over:

  1. There must be an initial value when declaring a variable with var

  1. var declaration must have an explicit target type, such as can not be used in the lamdba variable or array variable

The initial value of the variable declared by `var cannot be null

  1. var cannot declare non-representable types, including: null type, cross type (concept reference: and anonymous class type


This piece is rather embarrassing and less common. It is not convenient to explain too much before I can figure out it so as not to mislead everyone. For details, please refer to the description of the "unrepresentable" type in the original text:

 Http:// Articles are located at the "Non-denotable types" description


The above is about the new features of java10: the experience and description of the local variable type inference, more features please continue to follow this blog


Last modified: 2019年3月29日



Write a Reply or Comment

Your email address will not be published.