Created
March 22, 2020 14:47
-
-
Save affandes/690558fe9288865d386846728e08cafc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavaLang extends ProgrammingLang { | |
public void compileAndRun() { | |
System.out.println(JavaLang.class.getName()); | |
System.out.println("Compiling..."); | |
System.out.println("Running..."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JavascriptLang extends ProgrammingLang { | |
public void run() { | |
System.out.println(JavascriptLang.class.getName()); | |
System.out.println("Running..."); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProgrammingLang { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment