DictKey implements Dict<V>, Comment { @Override public final String name() { if (name == null) { final Field[] fields = klaz.getDeclaredFields(); for (final Field field : fields) { try { if (this == field.get(this)) { name = field.getName(); break; } } catch (final Exception e) { e.printStackTrace(); } } if (name == null) { name = "" + ordinal(); } } return name; } protected  DictKey(); private  DictKey(final String code, final String comment); static final Dict<?>[] values(); @Override final String name(); @Override final String guid(); @Override final int sequence(); @Override final int ordinal(); @Override final boolean equals(final Object dict); @Override final int hashCode(); static final Dict<?> fromOrdinal(final int ordinal); @Override final String code(); @Override final String getComment(); @Override final void setComment(String comment); static final Dict<?> UNKNOWN; }
@Test public void testName() { Value value = new Value(); String result1 = value.get(DictOne.TEST); Integer result2 = value.get(DictTwo.ONE); Integer result3 = value.get(DictTwo.TWO); assertEquals(DictOne.ONE.name(), "ONE"); assertEquals(DictOne.TEST.name(), "TEST"); System.out.println(DictOne.ONE.name() + " " + DictOne.ONE.ordinal()); System.out.println(DictTwo.TWO.name() + " " + DictTwo.TWO.ordinal()); System.out.println("guid : " + DictOne.ONE.guid()); System.out.println("guid : " + DictTwo.TWO.guid()); System.out.println("DictOne.TEST.guid() : " + DictOne.TEST.guid()); System.out.println("DictTwo.TEST.guid() : " + DictTwo.TEST.guid()); System.out.println("DictBase.X1.guid() : " + DictBase.X1.guid()); for (Dict<?> key : DictBase.values()) { System.out.println("# 0 # key : " + key.guid() + " / " + key.ordinal()); } for (Dict<?> key : DictOne.values()) { System.out.println("# 1 # key : " + key.guid() + " / " + key.ordinal()); } for (Dict<?> key : DictTwo.values()) { System.out.println("# 2 # key : " + key.guid() + " / " + key.ordinal()); } }