You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jep305.java 420B

12345678910111213141516171819202122
  1. class Orange {
  2. public String name1 = "orange";
  3. }
  4. class Apple {
  5. public String name2 = "apple";
  6. }
  7. public class Jep305 {
  8. public static void main(String []argv) {
  9. print(new Orange());
  10. print(new Apple());
  11. }
  12. public static void print(Object obj) {
  13. if (obj instanceof Orange o) {
  14. System.out.println(o.name1);
  15. } else if (obj instanceof Apple a) {
  16. System.out.println(a.name2);
  17. }
  18. }
  19. }