-
public
class ResponseBean<T> {
-
-
private int code;
-
private String message;
-
private String lang;
-
private String accessToken;
-
-
private String sign;
-
private int source;
-
private Date time;
-
private T value;
-
-
public ResponseBean() {
-
-
}
-
-
private ResponseBean(int code, T value) {
-
this(code, value,
"");
-
}
-
-
private ResponseBean(int code, T value, String message) {
-
this.time = new Date();
-
this.lang =
"zh_Cn";
-
this.source =
201;
-
this.code = code;
-
this.value = value;
-
this.message = message;
-
-
}
-
-
private ResponseBean(int code, String message) {
-
this.time = new Date();
-
this.lang =
"zh_Cn";
-
this.source =
201;
-
this.code = code;
-
this.message = message;
-
}
-
-
public static <T> ResponseBean<T> error(String msg, T
data) {
-
return new ResponseBean<>(
200,
data, msg);
-
}
-
-
省略
get()
set()方法
-
}
靜態方法不能訪問類中定義的泛型,如果靜態方法中數據類型不確定,可以在方法上定義泛型。
即上例中<T>就是聲名一個泛型T,之后兩個T是在使用泛型T。
原文地址:https://blog.csdn.net/m18870420619/article/details/79929316