有没有办法在类中检索静态类数组Network
(定义如下),并将每个类的属性传递class
给方法调用的参数kryo.register
?
public class Network {
// Classes to be transferred between the client and the server
public static class A {
public int id;
public String name;
}
public static class B {
public int id;
public int x;
public int y;
}
// Rest of the classes are defined over here
static public void register(EndPoint endPoint) {
Kryo kryo = endPoint.getKryo();
// typical way of registering classes so that kryonet can use it
// kryo.register(A.class);
// kryo.register(B.class);
// the rest of the classes are registered with kryonet over here
// my attempt at solving the question,
// but for some reason this doesn't work?
for(Object o : Network.class.getDeclaredClasses()) {
kryo.register(o.getClass());
}
}
}