你如何传递对类型'?的引用?

时间:2015-09-03 04:36:18

标签: java

我有一个方法来注册序列化类。我想从控件类中调用它,例如:

    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);
    }
}

或者,我可以轻松传递Control.SomeRequest.class,但我不确定如何实现其中任何一种。

1 个答案:

答案 0 :(得分:3)

"班级"的班级名称是Class

public static void RegisterClass(Class cls){
        kryo.register(cls);
}