简体   繁体   English

Java中的参数类型

[英]Parametric types in Java

我正在查看JasperReports的文档,但不理解以下方法的返回类型:

public java.lang.Class<?> getValueClass()

The method returns a Class object. 该方法返回一个Class对象。 The ? ? indicates that it can be any type of class. 指示它可以是任何类型的类。 You can read more about wildcards here . 您可以在此处阅读有关通配符的更多信息。 These Class objects are often utilized when you're dealing with reflection . 当您处理反射时,通常会使用这些Class对象。

Class<?> refers to any instance of Class. Class<?>引用Class的任何实例。 As compared to Class<? extends Collection> Class<? extends Collection> Class<? extends Collection> which would narrow the criteria down to a limited group of classes (those that extend Collection ). Class<? extends Collection> ,这会将条件缩小到一组有限的类(扩展Collection那些类)。

This is particularly important when calling methods like newInstance . 在调用诸如newInstance方法时,这一点尤其重要。 If you have Class<?> a and call a.newInstance() you'll get an Object . 如果您拥有Class<?> a并调用a.newInstance()您将获得一个Object if you have Class<? extends Collection> 如果您有Class<? extends Collection> Class<? extends Collection> and call b.newInstance() you'll get an instance of Collection . Class<? extends Collection>并调用b.newInstance()您将获得Collection一个实例。

It just returns an instance of a class. 它只是返回一个类的实例。 ? parameter which represents a generic wild card object ie it is a class of any type. 代表通用通配符对象的参数,即它是任何类型的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM