Skip to content

Instantly share code, notes, and snippets.

@affandes
Created March 22, 2020 14:47
Show Gist options
  • Save affandes/690558fe9288865d386846728e08cafc to your computer and use it in GitHub Desktop.
Save affandes/690558fe9288865d386846728e08cafc to your computer and use it in GitHub Desktop.
public class JavaLang extends ProgrammingLang {
public void compileAndRun() {
System.out.println(JavaLang.class.getName());
System.out.println("Compiling...");
System.out.println("Running...");
}
}
public class JavascriptLang extends ProgrammingLang {
public void run() {
System.out.println(JavascriptLang.class.getName());
System.out.println("Running...");
}
}
public class PatternMatching {
public static void main(String[] args) {
ProgrammingLang lang = new JavaLang();
if (lang instanceof JavaLang test) {
test.compileAndRun();
} else if (lang instanceof JavascriptLang test){
test.run();
}
}
}
public class ProgrammingLang {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment