1. 3

Java 12 just shipped JEP 325 (Switch Expressions), which unblocks JEP 305.

This let’s you do

if (obj instanceof String s) {
    // can use s here
} else {
    // can't use s here

Kotlin already has smart casts.

Java >9 is not the Java you remember.


  2. 2

    Is there any feature planned to solve instanceof over Generics? I have Checkstyle configured to flag any occurrence of instanceof as a High Priority bug, because Java’s Generics would mandate testing the entire inheritance hierarchy of both the class and the type parameter(s).


    if (obj instanceof MySubClass<? extends AnotherSubClass>)


    AnotherSubClass implements SomeInterface,AnotherInterface


    MySubClass<T extends AnotherInterface> extends SomeOtherClass<?>

    Things get messy quickly.