SlideShare a Scribd company logo
Java, what’s next?
by Stephan Janssen
• Founder of Devoxx

• Co-founder of Voxxed (Days)

• Co-founder Devoxx4Kids

• Java Champion

• Passionate Developer
Who am I ?
“The Future Is Complicated”
- John Rose , JVM Architect
“For Java to remain competitive it
must not just continue to move
forward — it must move forward
faster.”
- Mark Reinhold , Chief Architect of the Java Platform Group at Oracle
@Stephan007
More Java Releases
• Every 6 months feature releases (March, September)

• Long-term support releases every 3 years

• Next release for March 2018

• Details @ https://mreinhold.org/blog/forward-faster
@Stephan007
New Java Versioning
• Java SE 18.3
@Stephan007
• Project Amber

• Project Valhalla

• Project Panama - Interconnecting JVM and native code

• Project Loom - Make Concurrency simple(r) again!

• Project Metropolis - The holy Graal : a Java compiler & interpreter
How will this effect you?
@Stephan007
Project Amber
@Stephan007
Project Amber
• Local-Variable Type Inference
• Enhanced Enums
• Lambda Leftovers
• Pattern matching
• Switch expression
https://openjdk.java.net/projects/amber/
JEP 286 Local-Variable Type Inference (LVTI)
(Java 18.3 target release)
@Stephan007
Expanded Type Inference
List<String> empty = Collections.<String>emptyList();
List<String> empty = Collections.emptyList();
	 •	 Java 5: type inference for generic method type arguments
	 •	 Java 7: type inference for constructor type arguments
List<String> newList = new ArrayList<String>();
List<String> newList = new ArrayList<>();
	 •	 Java 8: type inference for lambda formals
Predicate<String> isEmpty = (String s) -> s.isEmpty();
Predicate<String> isEmpty = s -> s.isEmpty();
Brian Goetz @ http://bit.ly/2x3Wop9
@Stephan007
Local-Variable
Type Inference (JEP 286)
URL url = new URL(“https://devoxx.com");
URLConnection conn = url.openConnection();
Scanner scanner = new Scanner(conn.getInputStream(), “UTF-8”);
var url = new URL(“https://devoxx.com");
var conn = url.openConnection();
var scanner = new Scanner(conn.getInputStream(), “UTF-8”);
Brian Goetz @ http://bit.ly/2x3Wop9
@Stephan007
LVTI warnings
var x = { 1, 2, 3 }; // array initializer needs an explicit target-type
http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html
var x = null; // variable initializer is 'null'
var x; // cannot use 'var' on variable without initializer
var x = m(x); // cannot use 'var' on self-referencing variable
class var { } // as of release 9, 'var' is a restricted local variable type
@Stephan007
LVTI warnings
var[] x = s; // ‘var' is not allowed as an element type of an array
http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html
var x = 1, y = 2; // 'var' is not allowed in a compound declaration
var<String> list() { return null; } // illegal ref to restricted type 'var'
var x = () -> { }; // lambda expression needs an explicit target-type
@Stephan007
Hidden compiler option
-XDfind=local
Detect local variables whose declared type can be replaced by 'var'
http://mail.openjdk.java.net/pipermail/compiler-dev/2017-September/011060.html
class TestLVTI {

void test() {

String s2 = "";

for (String s = s2 ; s != "" ; ) { }

Object o = "";

}

}
TestLVTI.java:3: warning: Redundant type for local variable (replace
explicit type with 'var').
String s2 = "";
^
TestLVTI.java:4: warning: Redundant type for local variable (replace
explicit type with 'var').
for (String s = s2 ; s != "" ; ) { }
^
2 warnings
The type of o is not redundant!
@Stephan007
Other JVM Languages
Groovy Kotlin
def robot = new Robot() // mutable property
var name = “Hello”
// Read-only
// there's no 'new' keyword
val result = Address()
Scala & Lombok
// Mutable
var name = ”Hello”
// Read-only
val result = new Address()
BTW None of these JVM languages demand a semi-colon! 🤓
@Stephan007
Immutability?
http://mail.openjdk.java.net/pipermail/platform-jep-discuss/2016-December/000066.html
“Local variables are in reality the least
important place where we need more
help making things immutable. 

Local variables are immune to data races;
most locals are effectively final anyway.”

- Brian Goetz
@Stephan007
Project Amber
• JEP 286 Local-Variable Type Inference
• JEP 301 Enhanced Enums
• JEP 302 Lambda Leftovers
JEP 301 Enhanced Enums
http://openjdk.java.net/jeps/301
@Stephan007
Generic Enums
“Enhance the expressiveness of the enum construct in the
Java Language by allowing type-variables in enums, and
performing sharper type-checking for enum constants.”
- Maurizio Cimadamore
http://openjdk.java.net/jeps/301
@Stephan007
Enum enhancements
enum Argument<X> { // declares generic enum
STRING<String>(String.class),
INTEGER<Integer>(Integer.class), ... ;
Class<X> clazz;
Argument(Class<X> clazz) { this.clazz = clazz; }
Class<X> getClazz() { return clazz; }
}
Class<String> cs = Argument.STRING.getClazz(); //uses sharper typing of enum constant
http://openjdk.java.net/jeps/301
• Enum constants to carry constant-specific type information

• Constant-specific state and behavior. 
JEP 302 Lambda Leftovers
http://openjdk.java.net/jeps/302
@Stephan007
Treatment of underscores
• Use an uncerscore for unnamed lambda parameters
BiFunction<Integer, String, String> biss = (i, _) -> String.valueOf(i);
http://openjdk.java.net/jeps/302
@Stephan007
Shadowing a lambda parameter
• Allow lambda parameters to shadow variables in enclosing scopes.

• And locals declared with a lambda.
Map<String, Integer> msi = …
…
String key = computeSomeKey();
msi.comuteIfAbstent(key, key -> key.length()); // error!
http://openjdk.java.net/jeps/302
Pattern Matching
@Stephan007
String formatted = “unknown”;
if (constant instanceof Integer) {
int i = (Integer)constant;
formatted = String.format(“int %d”, i);
} else if (constant instanceof Byte) {
byte b = (Byte)constant;
formatted = String.format(“byte %d”, b);
} // …
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Pattern Matching
String formatted = “unknown”;
switch(constant) {
case Integer i :
formatted = String.format(“int %d”, i); break;
case Byte b :
formatted = String.format(“byte %d”, b); break;
// …
default: formatted = String.format(“Unknown: %s”, constant);
}
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Switch Expression
String formatted =
switch(constant) {
case Integer i -> String.format(“int %d”, i);
case Byte b -> String.format(“byte %d”, b);
case Long l -> String.format(“long %d”, l);
case Double d -> String.format(“double %f”, d);
case String s -> String.format(“string %s”, s);
default -> “Unknown”;
}
https://www.voxxed.com/2017/08/pattern-matching-java/
@Stephan007
Enhanced Switch Expression
Shape s = …
double area = switch (shape) {
case Circle(var center, var radius)
-> PI * radius * radius;
case Square(var lowerLeft, var edge)
-> edge * edge;
case Rect(var lowerLeft, var upperRight)
-> (upperRight.x - lowerLeft.x)
* (upperRight.y - lowerLeft.y);
// …
}
interface Shape { }
class Circle implements Shape {
Point center;
double radius;
}
class Square implements Shape {
Point lowerLeft;
double edge;
}
class Rect implements Shape {
Point lowerLeft;
Point upperRight;
}
JavaOne 2017 keynote : https://www.youtube.com/watch?v=Tf5rlIS6tkg
@Stephan007
val x = Random.nextInt(10)
val value = x match {
case 0 => “zero”
case 1 => "one"
case 2 => "two"
case _ => "many"
}
val value = when(x) {
0 -> “zero”
1 -> "one"
2 -> "two"
else -> "many"
}
@Stephan007
Valhalla
JEP 169 Value Types
“Codes like a class, works like an int!”
@Stephan007
public class Point {
final int x;
final int y;
}
http://cr.openjdk.java.net/~jrose/values/values-0.html
@Stephan007
public class Point {
final int x;
final int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public boolean equals(Object o) {
return o instanceof Point && x == ((Point)o).x && y == ((Point)o).y;
}
public int hashCode() {
return x + 31 * y;
}
public String toString() {
return String.format(“Point[%d,%d]”, x, y);
}
}
http://cr.openjdk.java.net/~jrose/values/values-0.html
Data Classes
“Just data, no identiy”
@Stephan007
public class Point(int x, int y) { }
http://cr.openjdk.java.net/~jrose/values/values-0.html
@Stephan007
Value Types Requirements
• Final, not extensible

• Only interface parents

• Immutable fields

• No identity

• Equality based on state
• No recursive definitions

• Non-nullable values

• Value semantics

• No (representational) polymorphism

• Multiple fields supported
JEP 218 Generics over Primitive Types
ArrayList<int>
@Stephan007
Generic type arguments are
constrained to extend Object
• Supporting generic primitive and value types arguments!
class Box<T> {
private final T t;
public Box(T t) { this.t = t; }
public T get() { return t; }
}
http://openjdk.java.net/jeps/218
• Suppose we want to specialize the following class with T=int
@Stephan007
• Project Amber

• Project Valhalla

• Project Panama - Interconnecting JVM and native code

• Project Loom - Make Concurrency simple(r) again!

• Project Metropolis - The holy Graal
Personal Wishlist
IF expressions
Even better, change all statements into expressions 🤓
Java, what's next?
@Stephan007
Resources :
Brian Goetz - Java Language Architect, Oracle John Rose, JVM Architect, Oracle
November 22nd, 2017

More Related Content

PDF
Solid and Sustainable Development in Scala
PPTX
TypeScript
PPT
Javascript
ODP
Scala Reflection & Runtime MetaProgramming
PPTX
002. Introducere in type script
PDF
A Re-Introduction to JavaScript
PDF
JavaScript Programming
ODP
A Tour Of Scala
Solid and Sustainable Development in Scala
TypeScript
Javascript
Scala Reflection & Runtime MetaProgramming
002. Introducere in type script
A Re-Introduction to JavaScript
JavaScript Programming
A Tour Of Scala

What's hot (19)

PDF
An Introduction to Scala for Java Developers
PDF
Scala coated JVM
ODP
10 Things I Hate About Scala
PPTX
PDF
Lambda: A Peek Under The Hood - Brian Goetz
PPTX
Scala fundamentals
PDF
Fundamental JavaScript [UTC, March 2014]
PPT
Scala presentationjune112011
PDF
Google Dart
PPTX
All You Need to Know About Type Script
PDF
Javascript
PDF
Scala : language of the future
PDF
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
PPT
JavaScript - An Introduction
PDF
camel-scala.pdf
PPT
The JavaScript Programming Language
PPTX
Javascript Basics
PPTX
Lecture 5 javascript
PDF
Introduction to Scala
An Introduction to Scala for Java Developers
Scala coated JVM
10 Things I Hate About Scala
Lambda: A Peek Under The Hood - Brian Goetz
Scala fundamentals
Fundamental JavaScript [UTC, March 2014]
Scala presentationjune112011
Google Dart
All You Need to Know About Type Script
Javascript
Scala : language of the future
JavaScript Tutorial For Beginners | JavaScript Training | JavaScript Programm...
JavaScript - An Introduction
camel-scala.pdf
The JavaScript Programming Language
Javascript Basics
Lecture 5 javascript
Introduction to Scala
Ad

Similar to Java, what's next? (20)

PPT
Scala uma poderosa linguagem para a jvm
PPTX
Scala Programming for Semantic Web Developers ESWC Semdev2015
PDF
Introduction to Scala for JCConf Taiwan
PDF
Short intro to scala and the play framework
PPTX
JavaScript.pptx
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
PDF
Introduction To Scala
PDF
Introduction to programming in scala
PDF
Inside the JVM - Follow the white rabbit! / Breizh JUG
PPTX
Intro to scala
PDF
Scala and jvm_languages_praveen_technologist
PDF
Scala for Java Programmers
PPTX
Knowledge of Javascript
KEY
Scala Introduction
PPTX
Introduction to Scala
PDF
JavaFX In Practice
PPTX
js.pptx
PPTX
Scala.js
PDF
Building Concurrent WebObjects applications with Scala
PPT
Scala Talk at FOSDEM 2009
Scala uma poderosa linguagem para a jvm
Scala Programming for Semantic Web Developers ESWC Semdev2015
Introduction to Scala for JCConf Taiwan
Short intro to scala and the play framework
JavaScript.pptx
BCS SPA 2010 - An Introduction to Scala for Java Developers
Introduction To Scala
Introduction to programming in scala
Inside the JVM - Follow the white rabbit! / Breizh JUG
Intro to scala
Scala and jvm_languages_praveen_technologist
Scala for Java Programmers
Knowledge of Javascript
Scala Introduction
Introduction to Scala
JavaFX In Practice
js.pptx
Scala.js
Building Concurrent WebObjects applications with Scala
Scala Talk at FOSDEM 2009
Ad

More from Stephan Janssen (17)

PPTX
Devoxx speaker training (June 27th, 2018)
PDF
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
PDF
The new Voxxed websites with JHipster, Angular and GitLab
KEY
Programming 4 kids
PDF
Devoxx2011 timesheet day3-4-5
PDF
Devoxx2011 timesheet day1-2
PDF
EJB 3.1 by Bert Ertman
PDF
BeJUG JAX-RS Event
PDF
Whats New In Java Ee 6
PDF
Glass Fishv3 March2010
PDF
Advanced Scrum
PDF
Scala by Luc Duponcheel
PDF
Intro To OSGi
PDF
Kick Start Jpa
PDF
BeJUG - Di With Spring
PDF
BeJUG - Spring 3 talk
PDF
BeJug.Org Java Generics
Devoxx speaker training (June 27th, 2018)
The new DeVoxxEd websites with JHipster, Angular & Kubernetes
The new Voxxed websites with JHipster, Angular and GitLab
Programming 4 kids
Devoxx2011 timesheet day3-4-5
Devoxx2011 timesheet day1-2
EJB 3.1 by Bert Ertman
BeJUG JAX-RS Event
Whats New In Java Ee 6
Glass Fishv3 March2010
Advanced Scrum
Scala by Luc Duponcheel
Intro To OSGi
Kick Start Jpa
BeJUG - Di With Spring
BeJUG - Spring 3 talk
BeJug.Org Java Generics

Recently uploaded (20)

PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
history of c programming in notes for students .pptx
PDF
System and Network Administration Chapter 2
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Introduction to Artificial Intelligence
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
ManageIQ - Sprint 268 Review - Slide Deck
ISO 45001 Occupational Health and Safety Management System
VVF-Customer-Presentation2025-Ver1.9.pptx
How Creative Agencies Leverage Project Management Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
history of c programming in notes for students .pptx
System and Network Administration Chapter 2
PTS Company Brochure 2025 (1).pdf.......
Adobe Illustrator 28.6 Crack My Vision of Vector Design
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Odoo Companies in India – Driving Business Transformation.pdf
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms I-SECS-1021-03
Introduction to Artificial Intelligence
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Operating system designcfffgfgggggggvggggggggg
Upgrade and Innovation Strategies for SAP ERP Customers

Java, what's next?

  • 1. Java, what’s next? by Stephan Janssen
  • 2. • Founder of Devoxx • Co-founder of Voxxed (Days) • Co-founder Devoxx4Kids • Java Champion • Passionate Developer Who am I ?
  • 3. “The Future Is Complicated” - John Rose , JVM Architect
  • 4. “For Java to remain competitive it must not just continue to move forward — it must move forward faster.” - Mark Reinhold , Chief Architect of the Java Platform Group at Oracle
  • 5. @Stephan007 More Java Releases • Every 6 months feature releases (March, September) • Long-term support releases every 3 years • Next release for March 2018 • Details @ https://mreinhold.org/blog/forward-faster
  • 7. @Stephan007 • Project Amber • Project Valhalla • Project Panama - Interconnecting JVM and native code • Project Loom - Make Concurrency simple(r) again! • Project Metropolis - The holy Graal : a Java compiler & interpreter
  • 8. How will this effect you?
  • 10. @Stephan007 Project Amber • Local-Variable Type Inference • Enhanced Enums • Lambda Leftovers • Pattern matching • Switch expression https://openjdk.java.net/projects/amber/
  • 11. JEP 286 Local-Variable Type Inference (LVTI) (Java 18.3 target release)
  • 12. @Stephan007 Expanded Type Inference List<String> empty = Collections.<String>emptyList(); List<String> empty = Collections.emptyList(); • Java 5: type inference for generic method type arguments • Java 7: type inference for constructor type arguments List<String> newList = new ArrayList<String>(); List<String> newList = new ArrayList<>(); • Java 8: type inference for lambda formals Predicate<String> isEmpty = (String s) -> s.isEmpty(); Predicate<String> isEmpty = s -> s.isEmpty(); Brian Goetz @ http://bit.ly/2x3Wop9
  • 13. @Stephan007 Local-Variable Type Inference (JEP 286) URL url = new URL(“https://devoxx.com"); URLConnection conn = url.openConnection(); Scanner scanner = new Scanner(conn.getInputStream(), “UTF-8”); var url = new URL(“https://devoxx.com"); var conn = url.openConnection(); var scanner = new Scanner(conn.getInputStream(), “UTF-8”); Brian Goetz @ http://bit.ly/2x3Wop9
  • 14. @Stephan007 LVTI warnings var x = { 1, 2, 3 }; // array initializer needs an explicit target-type http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html var x = null; // variable initializer is 'null' var x; // cannot use 'var' on variable without initializer var x = m(x); // cannot use 'var' on self-referencing variable class var { } // as of release 9, 'var' is a restricted local variable type
  • 15. @Stephan007 LVTI warnings var[] x = s; // ‘var' is not allowed as an element type of an array http://cr.openjdk.java.net/~mcimadamore/8177466/lvti-diags.html var x = 1, y = 2; // 'var' is not allowed in a compound declaration var<String> list() { return null; } // illegal ref to restricted type 'var' var x = () -> { }; // lambda expression needs an explicit target-type
  • 16. @Stephan007 Hidden compiler option -XDfind=local Detect local variables whose declared type can be replaced by 'var' http://mail.openjdk.java.net/pipermail/compiler-dev/2017-September/011060.html class TestLVTI { void test() { String s2 = ""; for (String s = s2 ; s != "" ; ) { } Object o = ""; } } TestLVTI.java:3: warning: Redundant type for local variable (replace explicit type with 'var'). String s2 = ""; ^ TestLVTI.java:4: warning: Redundant type for local variable (replace explicit type with 'var'). for (String s = s2 ; s != "" ; ) { } ^ 2 warnings The type of o is not redundant!
  • 17. @Stephan007 Other JVM Languages Groovy Kotlin def robot = new Robot() // mutable property var name = “Hello” // Read-only // there's no 'new' keyword val result = Address() Scala & Lombok // Mutable var name = ”Hello” // Read-only val result = new Address() BTW None of these JVM languages demand a semi-colon! 🤓
  • 18. @Stephan007 Immutability? http://mail.openjdk.java.net/pipermail/platform-jep-discuss/2016-December/000066.html “Local variables are in reality the least important place where we need more help making things immutable. Local variables are immune to data races; most locals are effectively final anyway.” - Brian Goetz
  • 19. @Stephan007 Project Amber • JEP 286 Local-Variable Type Inference • JEP 301 Enhanced Enums • JEP 302 Lambda Leftovers
  • 21. @Stephan007 Generic Enums “Enhance the expressiveness of the enum construct in the Java Language by allowing type-variables in enums, and performing sharper type-checking for enum constants.” - Maurizio Cimadamore http://openjdk.java.net/jeps/301
  • 22. @Stephan007 Enum enhancements enum Argument<X> { // declares generic enum STRING<String>(String.class), INTEGER<Integer>(Integer.class), ... ; Class<X> clazz; Argument(Class<X> clazz) { this.clazz = clazz; } Class<X> getClazz() { return clazz; } } Class<String> cs = Argument.STRING.getClazz(); //uses sharper typing of enum constant http://openjdk.java.net/jeps/301 • Enum constants to carry constant-specific type information • Constant-specific state and behavior. 
  • 24. @Stephan007 Treatment of underscores • Use an uncerscore for unnamed lambda parameters BiFunction<Integer, String, String> biss = (i, _) -> String.valueOf(i); http://openjdk.java.net/jeps/302
  • 25. @Stephan007 Shadowing a lambda parameter • Allow lambda parameters to shadow variables in enclosing scopes. • And locals declared with a lambda. Map<String, Integer> msi = … … String key = computeSomeKey(); msi.comuteIfAbstent(key, key -> key.length()); // error! http://openjdk.java.net/jeps/302
  • 27. @Stephan007 String formatted = “unknown”; if (constant instanceof Integer) { int i = (Integer)constant; formatted = String.format(“int %d”, i); } else if (constant instanceof Byte) { byte b = (Byte)constant; formatted = String.format(“byte %d”, b); } // … https://www.voxxed.com/2017/08/pattern-matching-java/
  • 28. @Stephan007 Pattern Matching String formatted = “unknown”; switch(constant) { case Integer i : formatted = String.format(“int %d”, i); break; case Byte b : formatted = String.format(“byte %d”, b); break; // … default: formatted = String.format(“Unknown: %s”, constant); } https://www.voxxed.com/2017/08/pattern-matching-java/
  • 29. @Stephan007 Switch Expression String formatted = switch(constant) { case Integer i -> String.format(“int %d”, i); case Byte b -> String.format(“byte %d”, b); case Long l -> String.format(“long %d”, l); case Double d -> String.format(“double %f”, d); case String s -> String.format(“string %s”, s); default -> “Unknown”; } https://www.voxxed.com/2017/08/pattern-matching-java/
  • 30. @Stephan007 Enhanced Switch Expression Shape s = … double area = switch (shape) { case Circle(var center, var radius) -> PI * radius * radius; case Square(var lowerLeft, var edge) -> edge * edge; case Rect(var lowerLeft, var upperRight) -> (upperRight.x - lowerLeft.x) * (upperRight.y - lowerLeft.y); // … } interface Shape { } class Circle implements Shape { Point center; double radius; } class Square implements Shape { Point lowerLeft; double edge; } class Rect implements Shape { Point lowerLeft; Point upperRight; } JavaOne 2017 keynote : https://www.youtube.com/watch?v=Tf5rlIS6tkg
  • 31. @Stephan007 val x = Random.nextInt(10) val value = x match { case 0 => “zero” case 1 => "one" case 2 => "two" case _ => "many" } val value = when(x) { 0 -> “zero” 1 -> "one" 2 -> "two" else -> "many" }
  • 33. JEP 169 Value Types “Codes like a class, works like an int!”
  • 34. @Stephan007 public class Point { final int x; final int y; } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 35. @Stephan007 public class Point { final int x; final int y; public Point(int x, int y) { this.x = x; this.y = y; } public boolean equals(Object o) { return o instanceof Point && x == ((Point)o).x && y == ((Point)o).y; } public int hashCode() { return x + 31 * y; } public String toString() { return String.format(“Point[%d,%d]”, x, y); } } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 36. Data Classes “Just data, no identiy”
  • 37. @Stephan007 public class Point(int x, int y) { } http://cr.openjdk.java.net/~jrose/values/values-0.html
  • 38. @Stephan007 Value Types Requirements • Final, not extensible • Only interface parents • Immutable fields • No identity • Equality based on state • No recursive definitions • Non-nullable values • Value semantics • No (representational) polymorphism • Multiple fields supported
  • 39. JEP 218 Generics over Primitive Types
  • 41. @Stephan007 Generic type arguments are constrained to extend Object • Supporting generic primitive and value types arguments! class Box<T> { private final T t; public Box(T t) { this.t = t; } public T get() { return t; } } http://openjdk.java.net/jeps/218 • Suppose we want to specialize the following class with T=int
  • 42. @Stephan007 • Project Amber • Project Valhalla • Project Panama - Interconnecting JVM and native code • Project Loom - Make Concurrency simple(r) again! • Project Metropolis - The holy Graal
  • 44. IF expressions Even better, change all statements into expressions 🤓
  • 46. @Stephan007 Resources : Brian Goetz - Java Language Architect, Oracle John Rose, JVM Architect, Oracle