DEV Community

From Java 8 to Java 15 in Ten Minutes

Philipp Gysel on December 07, 2020

This blog will give you samples of awesome new feature added since Java 7. I’ll showcase at least one major improvement for each Java version, all ...
Collapse
 
martinhaeusler profile image
Martin Häusler

"Instanceof without the cast" unfortunately doesn't work the way you describe in your example. You still need to assign a new variable name to the casted instance:

Object obj = new String("hello");
if (obj instanceof String mystr) {
  System.out.println("String length: " + mystr.length());
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
pmgysel profile image
Philipp Gysel

Thanks Martin, there's always a bug somewhere! I updated the code snippet as you suggested 😎

Collapse
 
martinhaeusler profile image
Martin Häusler

No problem. I really wish they did it in the way you've described. If you want this kind of inference, you'd have to use Kotlin; there it works this way.

Thread Thread
 
pmgysel profile image
Philipp Gysel

Oh well I‘m jeleous of the Kotlin developers😜 Anyways, happy coding!

Collapse
 
loiclefevre profile image
Loïc

Worth mentioning and up to jdk11 compatible - GraalVM Community Edition: graalvm.org/

The futur of Java :)

Collapse
 
pmgysel profile image
Philipp Gysel

Yes definititely, thanks for mentioning this one Loïc! I've heard GraalVM can help with faster startup times and lower memory consumption. This can help, especially for those large SpringBoot apps that take ~1minute to start. It's also an important part to move to FaaS.

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

All topics straight to the point! Thank you very much, Philipp!

Collapse
 
pmgysel profile image
Philipp Gysel

Thanks man appreciated!

Collapse
 
smilesavita profile image
smilesavita

Great article! Really helpful in remembering the major changes between Java 8 and Java 15. Thank you.

Collapse
 
kwereutosu profile image
Kwerenachi Utosu • Edited

Wow Philipp, a beautiful write up, top to bottom 👏🏼. Because of your article I’m definitely getting my hands on the newer Java versions, I’ve been too comfortable in Java 8

Collapse
 
pmgysel profile image
Philipp Gysel

Great to hear thanks😀 I'm sure you'll enjoy the benefits of the newer Java features!

Collapse
 
tuanphanhcm profile image
Phan Thanh Tuan

The new switch case syntax is applied in JDK 14, not 12. Kindly check it.

Collapse
 
pmgysel profile image
Philipp Gysel

Yes true. You can see this distinction in the table of contents (experimental feature). I didn't mention this again in the paragraph title to keep it short. Anyways, it's a great feature in my opinion, less verbose😀

Collapse
 
smilesavita profile image
smilesavita

This has become my go-to link whenever I have to refresh these features from Java 8 to Java 15 for interviews. Thank you.