Last active
February 24, 2020 08:28
-
-
Save mloza/f77dcd01c45fef553845e30e92f799fe to your computer and use it in GitHub Desktop.
Gist dla wpisu na temat nowości w Javie 14 znajdującego się pod adresem https://blog.mloza.pl/java-14-co-nowego-w-kolejnym-wydaniu/
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
VarHandle intHandle = MemoryHandles.varHandle(int.class, | |
ByteOrder.nativeOrder()); | |
try (MemorySegment segment = MemorySegment.allocateNative(100)) { | |
MemoryAddress base = segment.baseAddress(); | |
for (int i = 0; i < 25; i++) { | |
intHandle.set(base.addOffset(i * 4), i); | |
} | |
} |
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
if (obj instanceof String) { | |
String s = (String) obj; | |
System.out.println(s); | |
} |
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
if (obj instanceof String s) { | |
System.out.println(s); | |
} |
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
if (obj instanceof String s && s.length() > 5) { | |
return s.contains("Yes!"); | |
} |
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
String formatted = | |
switch (obj) { | |
case Integer i -> String.format("int %d", i); | |
case Byte b -> String.format("byte %d", b); | |
case Long l -> String.format("long %d", l); | |
case Double d -> String.format("double %f", d); | |
case String s -> String.format("String %s, s); | |
default -> String.format("Object %s", obj); | |
}; |
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
String text = """ | |
Lorem ipsum dolor sit amet, consectetur adipiscing \ | |
elit, sed do eiusmod tempor incididunt ut labore \ | |
et dolore magna aliqua.\ | |
"""; | |
String colors = """ | |
red \s | |
green\s | |
blue \s | |
"""; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment