samedi 14 novembre 2015

Entering .class after datatypes when using reflection in Java [duplicate]

This question already has an answer here:

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