请帮忙解释一下:Class<? extends Number> 中<>这一部分关于java泛型的用法。希望能提供一个详尽的例子。
Class<?extendsInsertSort>java.lang.Object.getClass()ReturnstheruntimeclassofthisObjec...
Class<? extends InsertSort> java.lang.Object.getClass()
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.
The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment:
Number n = 0;
Class<? extends Number> c = n.getClass();
Returns:
The Class object that represents the runtime class of this object. 展开
Returns the runtime class of this Object. The returned Class object is the object that is locked by static synchronized methods of the represented class.
The actual result type is Class<? extends |X|> where |X| is the erasure of the static type of the expression on which getClass is called. For example, no cast is required in this code fragment:
Number n = 0;
Class<? extends Number> c = n.getClass();
Returns:
The Class object that represents the runtime class of this object. 展开
1个回答
展开全部
泛型有点泛指的意思。比如说集合ArrayList中可以存放对象,可以存放字符,字符串等等东西。比如我们存放的是自己定义的Person类的对象,那么当我们取出来的时候就要对对象进行强制转换Person p = (Person)listname.get(1);这样才能使用p这个对象。如果我们使用了泛型,就说明告诉java这个list中存放的是Person类的实例:ArrayLIst<Person> listname = new ArrayList<Person>();这样在去的时候就不用进行强制转换了。总结就是告诉java该集合里面存放的是某一种类型的对象或者说数据。以上是个人浅薄的简介,望指正。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询