user1700440
user1700440

Reputation: 19

Parametric types in Java

I'm looking at the documentation of JasperReports and I do not understand the return type of the following method:

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

Upvotes: 0

Views: 963

Answers (3)

arshajii
arshajii

Reputation: 129557

The method returns a Class object. 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.

Upvotes: 3

Donald.McLean
Donald.McLean

Reputation: 899

Class<?> refers to any instance of Class. As compared to Class<? extends Collection> which would narrow the criteria down to a limited group of classes (those that extend Collection).

This is particularly important when calling methods like newInstance. If you have Class<?> a and call a.newInstance() you'll get an Object. if you have Class<? extends Collection> and call b.newInstance() you'll get an instance of Collection.

Upvotes: 1

sakthisundar
sakthisundar

Reputation: 3288

It just returns an instance of a class. ? parameter which represents a generic wild card object i.e it is a class of any type.

Upvotes: 0

Related Questions