0

I am not able to figure out how to declare a parameter in a function or a field in a class using ? wildcard without using any collection. For eg. I can write something like List l1 but how do I use ? without using List or any such collection.

  • 1
    Can you please show your code ? We have no clue what you did in your code. – Suresh Atta Aug 07 '14 at 06:25
  • The answer to question from your subject is "no". But the rest of your question is not clear to me. Please show your code and explain better your concrete problem. – AlexR Aug 07 '14 at 06:25

2 Answers2

1

A wildcard generic can be used with any generic type, for example Class<?>

public void myFunction(Class<?> theObject) {
  // your code goes here
}
Evan Knowles
  • 7,426
  • 2
  • 37
  • 71
0

Every parameterized class can accept wildcards. Just because collections are the most representative example of generics usage, you are not limited to them.

Usually, you use the ? wildcard when you're not sure about the actual parameter class and you want to avoid raw types.

Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43