我现在需要将一个类和一个byte绑定在一起 这样他们就能找到彼此(用两个hashmap)我现在想到的方式是class A{ ....}class B{ ....}....HashMap map1=new HashMap();HashMap map2=new HashMap();map1.put(A,1)map2.put(1,A)map1.put(B,2)map2.put(2,B)但是很明显这样写太丑了如果能通过注解找到类的话就可以 @record class A{ .... } @record class B{ .... } .... class map{ static { list= //a way to get all class which be annotation for(int i=0;i<list.length();i++){ map.put(list.get(i),i) } } static byte get(Object k){ map.get(k) } } //用的时候可以 class A{ .... { map.get(this) } }注解可以做到这种效果吗?对于这个问题还有什么更好的方法吗?
添加回答
举报
0/150
提交
取消