From the Java tutorial:
Finally, there's also a special kind of literal called a class literal, formed by taking a type name and appending "
.class
"; for example,String.class
. This refers to the object (of typeClass
) that represents the type itself.
To what type of variable can this literal be assigned to?
Please give a small example if possible.
A class literal is an expression consisting of the name of a class, interface, array, or primitive type followed by a . and the token class . The type of a class literal is Class .
Literal in Java is a synthetic representation of boolean, numeric, character, or string data. It is a means of expressing particular values in the program, such as an integer variable named ''/count is assigned an integer value in the following statement. int count = 0; A literal '0' represents the value zero.
The non-erased type of Foo. class would be java.
There are 4 types of integer literals in Java: binary (base 2) decimal (base 10) octal (base 8)
Class<String> c = String.class;
Check out the Javadoc for java.lang.Class
to see what you can do with one of these little guys - mostly related to reflection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With