This question already has an answer here:
- What does int.class mean 3 answers
I am trying to learn reflection in Java but there is something that puzzles me. Why do we have to enter ".class" after the datatype of the parameter of the method that we are trying to access? For example:
Method personMethod = person.getClass().getDeclaredMethod("returnRandomInt", int.class);
Why do we have to type ".class" after int? I am not using int's wrapper class "Integer", I am using the primitive datatype "int". So, why do I have to enter ".class" here? What purpose does it serve?
Thank you.
By the way, I've only been learning Java for a year, so I am still considered a beginner.
Aucun commentaire:
Enregistrer un commentaire