aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs196/java14/Jep305.java
blob: 3c526aef3840b30c15feec5956a6c8b3dd3b6b21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Orange {
  public String name1 = "orange";
}

class Apple {
  public String name2 = "apple";
}

public class Jep305 {
  public static void main(String []argv) {
    print(new Orange());
    print(new Apple());
  }

  public static void print(Object obj) {
    if (obj instanceof Orange o) {
      System.out.println(o.name1);
    } else if (obj instanceof Apple a) {
      System.out.println(a.name2);
    }
  }
}