import java.util.*;
import java.util.stream.*;
public class ModernJavaDemo {
public record Person(String name, int age) {}
public sealed interface Shape
permits Circle, Rectangle {}
public record Circle(double radius) implements Shape {}
public record Rectangle(double width, double height) implements Shape {}
public static void main(String[] args) {
List<Person> people = List.of(
new Person("Alice", 30),
new Person("Bob", 25),
new Person("Charlie", 35)
);
var averageAge = people.stream()
.filter(p -> p.age() > 20)
.mapToInt(Person::age)
.average()
.orElse(0);
System.out.println("Average age: " + averageAge);
Shape shape = new Circle(5.0);
String description = switch (shape) {
case Circle c -> "Circle with radius " + c.radius();
case Rectangle r -> "Rectangle " + r.width() + "x" + r.height();
};
System.out.println(description);
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
executor.submit(() -> System.out.println("Running on virtual thread"));
}
}
}