Skip to content

Instantly share code, notes, and snippets.

@up1
Last active March 20, 2026 06:51
Show Gist options
  • Select an option

  • Save up1/765a8688f7648fad35bcb8a8045dcfe5 to your computer and use it in GitHub Desktop.

Select an option

Save up1/765a8688f7648fad35bcb8a8045dcfe5 to your computer and use it in GitHub Desktop.
Hello Java 26
// Java 25
$java -version
openjdk version "25" 2025-09-16
OpenJDK Runtime Environment (build 25+35-3488)
OpenJDK 64-Bit Server VM (build 25+35-3488, mixed mode, sharing)
$java Hello.java
Hello
Goodbye
// Java 26
$java -version
openjdk version "26" 2026-03-17
OpenJDK Runtime Environment (build 26+35-2893)
OpenJDK 64-Bit Server VM (build 26+35-2893, mixed mode, sharing)
$java Hello.java
Hello
WARNING: Final field finalField in class Demo1 has been mutated reflectively by class Hello in unnamed module @6c3f5566 (file:/Users/somkiatpuisungnoen/data/slide/java/learn/java26/Hello.java)
WARNING: Use --enable-final-field-mutation=ALL-UNNAMED to avoid a warning
WARNING: Mutating final fields will be blocked in a future release unless final field mutation is enabled
Goodbye
## Disable การแก้ไข
$java --illegal-final-field-mutation=deny Hello.java
var client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_3)
.build();
var request = HttpRequest.newBuilder(URI.create("https://somkiat.cc"))
.version(HttpClient.Version.HTTP_3)
.GET().build();
import java.util.logging.Logger;
class OrderController {
// OLD:
// private Logger logger = null;
// NEW:
private final LazyConstant<Logger> logger = LazyConstant
.of(() -> Logger.getLogger(OrderController.class.getName()));
public void submitOrder() {
// Access the constant value using get()
logger.get().info("Order started");
}
}
public class DemoLazy {
public static void main(String[] args) {
OrderController controller = new OrderController();
controller.submitOrder();
}
}
class Demo1 {
final String finalField;
Demo1() {
finalField = "Hello";
}
}
public class Hello {
void main() throws Exception {
java.lang.reflect.Field f = Demo1.class.getDeclaredField("finalField");
f.setAccessible(true);
Demo1 obj = new Demo1();
System.out.println(obj.finalField); // Prints "Hello"
f.set(obj, "Goodbye");
System.out.println(obj.finalField); // Prints "Goodbye"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment