publicclassLazyMapimplementsSerializable {protectedLazyMap(Map map,Transformer factory) { super(map);if (factory ==null) {thrownewIllegalArgumentException("Factory must not be null"); }this.factory= factory; }publicObjectget(Object key) {// create value for key if key is not currently in the mapif (map.containsKey(key) ==false) {Object value =factory.transform(key);map.put(key, value);return value; }returnmap.get(key); }}
publicObjectinvoke(Object proxy,Method method,Object[] args) {String member =method.getName();Class<?>[] paramTypes =method.getParameterTypes();// Handle Object and Annotation methodsif (member.equals("equals") &¶mTypes.length==1&& paramTypes[0] ==Object.class)returnequalsImpl(args[0]);if (paramTypes.length!=0)thrownewAssertionError("Too many parameters for an annotation method");switch(member) {case"toString":returntoStringImpl();case"hashCode":returnhashCodeImpl();case"annotationType":return type; }// Handle annotation member accessorsObject result =memberValues.get(member);// ....}