[2024 dev2next] project amber

Speaker: Neha Sardana

For more see the table of contents


General

  • Aim: Code is clear like Amber
  • Showed old release cadence ncluding 5 year gap from 2006-2011

Many projects

  • Amber – small incrememenal language enhanceents
  • Loom – lightweight concurrency and virtual threads
  • Valhala – value types and generic collections
  • Panama – native code

Goals of Amber

  • Boost productivity – less boilerplate
  • Improve code readability
  • Support long term evolution
  • Maintain language consistency

Preview features

  • Experimental but final features
  • Have to enable preview features to use

Local variable type inference

  • var – JEP-286
  • var for lambda parameters JEP-323
  • variable names more important because don’t have the type

Data handling

  • Records – 359, 384, 395
    • Data classes
  • Immutable and final
  • IdIeal for data transfer objects
  • Sealed classes – JEP 360, 397, 409
  • Controlled inheritance
  • Improved code safety
  • Enhanced pattern matching
  • Text blocks – 355, 368, 378
  • Multi line string simplification
  • Improved readability
  • Automatic formatting
  • Remember when had to put SQL in a String
  • String templates 430, 459, 465 – withdrawn)
  • Not available in Java 23. Would have simplified string concat, improved safety and enhanced readability
  • Withdrawn due to issues
  • If some back, will have new design/syntax

Control flow

  • Switch expressions 325, 354, 361
  • Simplified syntax
  • Return values
  • Exhaustiveness checking
  • Pattern matching for instance of 305, 375, 394
  • Eliminates casting
  • Improves readability
  • Safer type handling
  • Pattern matching for switch 406, 420, 427, 433, 441
  • Some of the JEPs didn’t change; just wanted more user feedback
  • Primitives types in patterns, instanceof, and switch 445
  • preview in 23
  • can use int to match instead of having to use Integer
  • Record patterns – 405, 432, 440
  • Declare record fields in same line so can use in instance of without having to reference
  • Pattern matching for data decomposition
  • Can use instance of and && in a lamdba; doesn’t have to be in if statement
  • Works with instanceof and switch
  • Unnamed patterns and variable 443, 456
  • Use _ instead of name to show unused
  • Clearer that want to ignore data
  • Enhanced pattern matching flexibility
  • Can use _ in lambda variable, catch block, etc as well

New language features

  • Implicitly declared classes and instance main methods – 445, 463, 477
  • In preview
  • void main() – no class, no public/static/params
  • println() instead of System.out – in void main(), get that static import without having to have the import
  • Reduces boilerplate
  • Module import declarations – 476
  • In preview
  • import module java.base;
  • Simplifies module usage
  • Let’s use classes in module.
  • If conflict, need to explicitly import that class
  • Statements before super -> Flexible constructor bodies 447, 482
  • feature renamed between versions of Java
  • Flexibile initialization
  • Improved code flow
  • Enhanced control

Future

  • Derived record creation 468
  • in preview
  • allow extending records – dervices most values from original
  • Person x – original with { email = “e”; };
  • Simplify record inheritance
  • Reuseable code

My take

I had seen this talk in NY and came to support Neha. It’s still good :). I like that she had a lot of examples. Mentioning Scala a lot was fine, More opportunities to learn..