为了在接口中实现所有方法,我创建了一个实现接口的抽象类,然后让其他类扩展抽象类并仅覆盖所需的方法.
我正在为我的应用程序构建API / Framework.
我想将作为IMyInterface接口实例的类添加到ArrayList:
ArrayList<Class<IMyInterface>> classes = new ArrayList<>(); classes.add(MyClass.class);
这是MyClass
class MyClass extends AbstractIMyInterface {}
这是AbstractIMyInterface
class AbstractIMyInterface implements IMyInterface {}
到目前为止这似乎不可能.我上面的方法不起作用:
add (java.lang.class<com.app.IMyInterface>)
in ArrayList cannot be applied to
(java.lang.class<com.myapp.plugin.plugin_a.MyClass>)