相关疑难解决方法(0)

如何交互ArrayList <Class <?扩展IMyInterface >>

我有一个ArrayList<Class<? extends IMyInterface>> classes = new ArrayList<>();.当我尝试迭代它时,我得到:

Incopatible types:  
Required: java.lang.Class <? extends IMyInterface>  
Found: IMyInterface  
Run Code Online (Sandbox Code Playgroud)

我的迭代

for (IMyInterface iMyInterface : IMyInterface.getMyPluggables()) {}
Run Code Online (Sandbox Code Playgroud)

红色代码警告突出显示(Android Studio)

Error:(35, 90) error: incompatible types: Class<? extends IMyInterface> cannot be converted to IMyInterface  
Run Code Online (Sandbox Code Playgroud)

我想要

ArrayList<Class<? extends IMyInterface>> classes = new ArrayList<>();

for (Class<? extends IMyInterface> myClass : classes) {
    if (myClass instanceof IMyInterface) {
        View revPluggableViewLL = myClass.getMyInterfaceMethod();
    }
}
Run Code Online (Sandbox Code Playgroud)

错误

Inconvertible types; cannot cast 'java.lang.Class<capture<? extends com.myapp.IMyInterface>>' to 'com.myapp.IMyInterface'  
Run Code Online (Sandbox Code Playgroud)

我该怎么去迭代呢?

谢谢大家.

java iteration interface arraylist

2
推荐指数
1
解决办法
142
查看次数

标签 统计

arraylist ×1

interface ×1

iteration ×1

java ×1