How has Optional changed in recent Java versions?

Optional in Java has evolved to provide better null safety and functional programming capabilities. This includes enhancements in the use of Optional methods and improved performance for nullable types.
Optional, Java, null safety, functional programming, Java 8, Java 9, Java 10, enhancements
// Example of using Optional in Java import java.util.Optional; public class OptionalExample { public static void main(String[] args) { Optional optionalName = Optional.ofNullable(getName()); // If name is present, print it; otherwise, print a default message String name = optionalName.orElse("Default Name"); System.out.println(name); } private static String getName() { return null; // Simulating a scenario where the name is not present } }

Optional Java null safety functional programming Java 8 Java 9 Java 10 enhancements