package fixtures; import java.util.*; import java.util.stream.*; public class Valid { public static class Person { private final int id; private final String name; private final String email; public Person(int id, String name, String email) { this.id = id; this.name = name; this.email = email; } public int getId() { return id; } public String getName() { return name; } public String getEmail() { return email; } @Override public String toString() { return name + " <" + email + ">"; } } public static class Repository { private final Map items = new HashMap<>(); public void add(int key, T item) { items.put(key, item); } public Optional find(int key) { return Optional.ofNullable(items.get(key)); } public List getAll() { return new ArrayList<>(items.values()); } } public static int add(int a, int b) { return a + b; } public static void main(String[] args) { Repository repo = new Repository<>(); repo.add(1, new Person(1, "Alice", "alice@example.com")); repo.add(2, new Person(2, "Bob", "bob@example.com")); repo.getAll().stream() .map(Person::getName) .forEach(System.out::println); System.out.println("3 + 4 = " + add(3, 4)); } }