为java创建一个通用响应项

时间:2016-03-16 19:15:09

标签: java android variables generics response

这是我的问题:我的英语不是最好的。

为java创建一个通用响应项。

public class GenericResponse(){

  private "generic class" a;

}

我需要在构造函数方法中设置"类"变量generic的类型。

GenericResponse(t.class){
   a = t.class;
}

1 个答案:

答案 0 :(得分:0)

最接近你的是在java中命名为通用数据类型... 它看起来像:

public class GenericTypeData<T> {

    private final T a;

    public GenericTypeData(T a) {
        this.a = a;
    }

    public static void main(String[] args) {
          GenericTypeData<String> string = new GenericTypeData<String>("am a String");
          GenericTypeData<Integer> intType = new GenericTypeData<Integer>(122);
    }

}