Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does <?> stand for in Java? [duplicate]

Tags:

java

raw-types

Possible Duplicate:
Java Generics

In Eclipse, I am given warnings for using 'rawtypes' and one of it's fixes is to add <?>. For example:

    Class parameter = String.class;
    //Eclipse would suggest a fix by converting to the following:
    Class<?> parameter = String.class;

What does this <?> actually mean?

like image 907
trigoman Avatar asked Jun 27 '11 14:06

trigoman


People also ask

What does class <?> Mean in Java?

What Does Class Mean? A class — in the context of Java — is a template used to create objects and to define object data types and methods. Classes are categories, and objects are items within each category. All class objects should have the basic class properties.

What does <? Super t mean in Java?

super T denotes an unknown type that is a supertype of T (or T itself; remember that the supertype relation is reflexive). It is the dual of the bounded wildcards we've been using, where we use ? extends T to denote an unknown type that is a subtype of T .

What does %% mean in Java?

%% means % character for java. util. Formatter pattern. Since % denotes the beginning of format specifier %% is used to escape % char.

What does a || b mean in Java?

It is a binary OR Operator and copies a bit to the result it exists in either operands. Assume integer variable A holds 60 and variable B holds 13 then. (A | B) will give 61 which is 0011 1101. Whereas || is a logical OR operator and operates on boolean operands.


2 Answers

Class<?> should be interpreted as a Class of something, but the something isn't known or cared about.

It's the use of Java generic types. Class in Java 5 or greater is a parameterized type, so the compiler expects a type parameter. Class<String> would work in the specific context of your code, but again, in many cases you don't care about the actual type parameter, so you can just use Class<?> which is telling the compiler that you know Class expects a type parameter, but you don't care what the parameter is.

like image 90
Jason S Avatar answered Sep 20 '22 12:09

Jason S


Raw types refer to using a generic type without specifying a type parameter. For example, List is a raw type, while List<String> is a parameterized type

See this document for more info: http://www.javapractices.com/topic/TopicAction.do?Id=224

like image 30
Naftali Avatar answered Sep 19 '22 12:09

Naftali