1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package eternal.fire;
import java.util.HashMap; import java.util.Map;
public class Student { private static final Map<String, Student> cache = new HashMap<>(); private final int id; private final String name;
public Student(int id, String name) { this.id = id; this.name = name; } public static Student createStudent(int id, String name) { String key = id + name; Student student = cache.get(key); if (student == null) { cache.put(id + name, new Student(id, name)); return cache.get(key); } else { return cache.get(key); } }
}
|