Java class type
•
Java
I have a piece of valid code. I want to ask what happened?
Class<?> normalFormClass = null;
– - add – –
The wildcard "" is a confusing part for me Why use it instead of using it (generics)?
Solution
This means that it can be any type of class? Is a wildcard that represents a collection of all types, or "any" So you can do this later
Integer normalForm = new Integer(); normalFormClass = normalForm.getClass();
or
String normalForm = new String(); normalFormClass = normalForm.getClass();
If you don't understand generics on Java, read http://java.sun.com/developer/technicalArticles/J2SE/generics/
As for why, I think it may strictly express that you use generics anywhere, your code is incompatible with the old java version, or it may close some ide that triggers happiness yes,
Class foo
and
Class<?> foo
Is equivalent
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码