Skip to content

Instantly share code, notes, and snippets.

@mloza
Last active February 24, 2020 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mloza/f77dcd01c45fef553845e30e92f799fe to your computer and use it in GitHub Desktop.
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/
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);
}
}
if (obj instanceof String) {
String s = (String) obj;
System.out.println(s);
}
if (obj instanceof String s) {
System.out.println(s);
}
if (obj instanceof String s && s.length() > 5) {
return s.contains("Yes!");
}
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);
};
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