Class
instance gets created in a per-type constant pool, when particular class(X
) gets loaded.
javac
compiles this syntax int.class
to point to object that Integer.TYPE
points to.
Below code, get access to parameterise(int
) constructor of class X
.
Class c = X.class;
Constructor cons = c.getConstructor(int.class);
cons.newInstance(10);
In the above code, I did not understand the role of int.class
argument, under the hood. Why int.class
is being passed as argument?
Aucun commentaire:
Enregistrer un commentaire