java - What does int.class mean -
in java int, float , etc., primitive types. wrapper classes used in case need use generics. still following declaration works in java,
class<integer> intclass=int.class how can call int.class though primitive type?
a primitive becoming object
for primitives, there class objects available constants named type in corresponding wrapper classes -- i.e. int.class changed java.lang.integer.type . other types, compiler creates private member variable in class being compiled hold class object, , generates code initialize member using class.forname() .
found discussion
and nice discussion here , example covered in link.
a few words there :
how can class primitive? let's confuse things bit more. can access class object representing defined class coding, say:
equation.class // returns equation class object but, can say:
int.class obtain class object name "int". note have not sent getclass() method object; have used reserved word built-in primitive type (int) and, using dot notation, accessed class "field." , returns class object!
Comments
Post a Comment