[英]How do you pass a reference to type 'class'?
I have a method that registers classes for serialization. 我有一个注册类以进行序列化的方法。 I want to call this from a control class, something like:
我想从控件类中调用它,例如:
public static void main(String[] args) {
Registrar.RegisterClass(Control.SomeRequest);
Registrar.RegisterClass(Control.SomeResponse);
Sender testServer = new Sender();
Receiver testClient = new Receiver();
testServer.StartServer();
testClient.StartClient();
}
public static class SomeRequest {
public String text;
}
public static class SomeResponse {
public String text;
}
---------------------------------------------
public class Registrar {
static Kryo kryo = client.getKryo();
public static void RegisterClass(??? cls){
kryo.register(cls.class);
}
}
Alternatively, I could pass in Control.SomeRequest.class
just as easy, though I'm not sure how to achieve either of these. 另外,我也可以轻松传递
Control.SomeRequest.class
,尽管我不确定如何实现这两个目标。
The class name of "classes" is Class
“ classes”的类名称是
Class
public static void RegisterClass(Class cls){
kryo.register(cls);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.