Jewel Java

Java Software Engineer

Line of Business Public

Merlin Bögershausen / @mboegie

What is Amber again?

Amber

JDK Projects?

A Project is a collaborative effort to produce a specific artifact, which may be a body of code, or documentation, or some other material.

— OpenJDK Bylaws section 6

Project Amber?

The goal of Project Amber is to explore and incubate smaller, productivity-oriented Java language features

— Project Amber main page

JEP?

An enhancement is an effort to design and implement a nontrivial change to the JDK code base or to do some other kind of work whose goals, progress, and result are worth communicating broadly

— JEP 1

Ambers' Syntactic Sugar

Bilder PPT BigDateMMs

JEP 286

List<String> lineList = new ArrayList<String>();
// less duplication
var lines = new ArrayList<String>();
final var readLines = lines.size();

JEP 323

BiConsumer<Consumer<String>, String> sink
    = (x, y) -> x.accept(y);
// now with Annotations!
BiConsumer<Consumer<String>, String> safeSink
    = (@Nonnull var x, var y) -> x.accept(y);

JEP 378

Multi-line Text Blocks landed in Java 11

String helloWorldResponse = """
    <html>
        <body>
            <p>Hello, world</p>
        </body>
    </html>
    """;

JEP 361

Switch Expressions landed in Java 14

int j = switch (day) {// enum Days {MONDAY, …}
  case null, MONDAY -> 0;
  case TUESDAY -> 1;
  default -> {
    int k = day.toString().length();
    yield k;
  }
};

Type Enhancements

Bilder PPT Scribble

JEP 359

Records landed in Java 16

record Range(int low, int high) {
  Range {
    if (low > high)
      throw new IllegalArgumentException(/*...*/);
  }
  int lenght() { return high - low; }
}

JEP 359

Records landed in Java 16

record Range(List<Integer> values) {
  Range(List<Integer> values) {
    this.values = List.copyOf(values);
  }
  Range(Integer i1, Integer i2) {
    this(List.of(i1,i2));
  }
}

JEP 409

Sealed Classes landed in Java 17

sealed interface Shape {
  sealed class Cornered implements Shape
    permits Rectangle, Square{}
  final class Weirdo implements Shape {}
}
non-sealed class Rectangle implements Cornered {}
record Square(int h) implements Cornered {}

Pattern Matching

Bilder PPT LottoCode

JEP 394

landed in Java 16

if (o instanceof Triangle t) {
    System.out.println("Area: " + t.calculateArea());
} else if (!(o instanceof String str)) {
    System.out.println("Not Triangle or String ");
} else {
    System.out.println("String value is:" + str);
}

JEP 427

3rd Preview in Java 19

switch (s) {
  case Triangle t when t.calculateArea() > 100 ->
    System.out.println("Large");
  case Triangle t -> System.out.println("Small");
  default -> System.out.println("Non-triangle");
}

JEP 405

1st Preview in Java 19

record Point(int x, int y) {}

void printSum(Object o) {
  if (o instanceof Point(int x, var y)) {
    System.out.println(x+y);
  }
}

From the Dreams

Snooze

JEP 302

Lambda Leftovers no target, yet

BiFunction<Integer, String, String> f
    = (i, _) -> String.valueOf(i);

Concise Method Bodies

class User {
    private final String name;
    Integer nameLength() = name::length;
}

String Template

Jim Laskey and Brian Goetz Sep. 2012

int x = 10, y = 20;
TemplatedString s = "\{x} + \{y} = \{x + y}";
     // Concatenation: 10 + 20 = 30

Contact

Me

@MBoegi // MBoegers

adesso

Infos // DevBlog

Jobs

qrcode adesso jobs

Image Credits