import static java.lang.System.out; import java.util.Optional; class HelloWorld { public static void main(String[] args) { var name = at(args, 0).orElse("World"); out.printf("Hello, %s!%n", name); } public static <T> Optional<T> at(T[] array, int index) { try { return Optional.of(array[index]); } catch (ArrayIndexOutOfBoundsException | NullPointerException e) { return Optional.empty(); } } }