Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
好的,我想要一个以类的对象作为参数的方法。我怎样才能实现这个方法接受一个类的任何对象(以便该方法是通用的)?
我尝试使用类型参数,但总是收到错误消息:“意外类型,必需类,找到类型参数”。我必须使用类似的东西吗
Class<R>
有什么好的例子吗?
我不确定我是否理解您的问题,但也许是这样:
public <T> void foo(T param)
或更复杂的版本:
public <T> Class<? extends T> pickOne(Collection<Class<? extends T>> classes)
问候莱昂