public abstract class AbstractRESTClientService<E extends IDable<String>>
implements GenericService<E, String> {
private Class<E> classType;
private Class<E[]> classArray;
private String controllerPath;
public AbstractRESTClientService(final Class<E> classType,
final Class<E[]> classArray,
final String controllerPath) {
this.classType = classType;
this.classArray = classArray;
this.controllerPath = controllerPath;
this.webService = new GenericWebClientService<E>();
}
// ... other methods
}
有没有一种方法可以将classType操纵为classArray,这样我就不需要将classArray作为参数传递了?
最佳答案
我讨厌认为这是最好的方法,但是这就是我的处理方法。
public abstract class AbstractRESTClientService<E extends IDable<String>>
implements GenericService<E, String> {
private Class<E> classType;
private Class<E[]> classArray;
private String controllerPath;
@SuppressWarnings("unchecked")
public AbstractRESTClientService(final Class<E[]> classArray,
final String controllerPath) {
this.classType = (Class<E>) classArray.getComponentType();
this.classArray = classArray;
this.controllerPath = controllerPath;
this.webService = new GenericWebClientService<E>();
}
// ... other methods
}
关于java - 将精良的Class <E>转换为Class <E []>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36057937/