传递对象子类型(Passing objects subclass type)

编程入门 行业动态 更新时间:2024-10-11 17:30:09
传递对象子类型(Passing objects subclass type) java

我正在使用一个类类型作为参数的函数:

我试图传递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, ???);

I am working with a function that takes a class type as parameter:

I am trying to pass getSpans() the specific subclass of the Object "type."

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

更好地使用第二个例子。

Yes, just use type.class. It will return the Class object of the type variable. Also try type.getClass().class.

http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html

Better use the 2nd example.

更多推荐

本文发布于:2023-07-18 04:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1154795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   类型   Passing   type   subclass

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!