我正在使用一个以类类型作为参数的函数:
我试图将对象“类型”的特定子类传递给 getSpans()。
Spannable ss;
Object type;
int start;
int end;
//Assume above variables properly initialized.
....
//getSpans(int start, int end, Class<T> type)
ss.getSpans(start, end, ???);
最佳答案
是的,只需使用type.class
。它将返回类型变量的 Class 对象。还可以尝试 type.getClass().class
。
http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html
最好使用第二个示例。
关于java - 传递对象子类类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21270568/