Created
April 11, 2021 20:01
-
-
Save DRSchlaubi/a54ec48d33e25d5d52c78a1dc2a68247 to your computer and use it in GitHub Desktop.
Java 8 is outdated ;)
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
// alt | |
void onCommand(CommandSender sender) { | |
if (sender instanceof Player) { | |
Player player = (Player) sender; | |
} | |
} | |
// neu | |
void onCommand(CommandSender sender) { | |
if (sender instanceof Player player) { | |
player.doSomething(); // player wird zu PLayer gecasted | |
} | |
} | |
// Alt | |
String input = "test"; | |
String result; | |
switch (input) { | |
case "te": | |
case "est": | |
result = "te est"; | |
break; | |
case "tEsT": | |
result = "TeSt"; | |
break; | |
case "test": | |
result = "test"; | |
break; | |
} | |
// neu | |
String input = "test"; | |
String result = switch (input) { | |
case "te", case "est" -> "te est"; | |
case "tEsT" -> "TeSt"; | |
case "test" -> "test"; | |
} | |
// Alt | |
BufferedReader reader = new BufferedReader(); | |
// neu | |
var reader = new BufferedReader(); | |
// Alt | |
List<String> list = new ArrayList<>(); | |
list.add("a"); | |
list.add("a"); | |
list.add("a"); | |
list.add("a"); | |
// Neu | |
List<String> list = List.of("a", "a", "a", "a"); | |
// Alt | |
String sql = "SELECT * FROM table \n" + | |
WHERE x = y"; | |
// Neu | |
String sql = """SELECT * FROM table | |
WHERE x = y";""" | |
//Alt | |
ObjectThatHasFieldCalledI a; | |
a.i = "test; // => npe weil a ist null | |
java.lang.NullPointerException: null | |
<stacktrace> | |
//neu | |
ObjectThatHasFieldCalledI a; | |
a.i = "test; // => npe weil a ist null | |
java.lang.NullPointerException: Cannot assign field "i" because "a" is null | |
<stacktrace> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment