首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >精巧的Class<E> E[] Class<E[]>

精巧的Class<E> E[] Class<E[]>
EN

Stack Overflow用户
提问于 2016-03-17 10:33:32
回答 1查看 69关注 0票数 2
代码语言:javascript
复制
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作为参数传入?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-17 17:09:07

我不认为这是最好的方法,但我是这样处理的。

代码语言:javascript
复制
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
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36057937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档