+ 8

How the reflection concept in java works can anyone explain this with some great example????

11th Mar 2017, 5:15 PM
Sathish Kumar
Sathish Kumar - avatar
3 Respostas
+ 4
s please can I have the code
12th Mar 2017, 4:27 AM
Sathish Kumar
Sathish Kumar - avatar
+ 1
Reflection provides you the ability to handle classes, objects and members runtime. For example, you can list all methods of a class, their types of parameters, return type, do those methods have a certain annotation, or, check for a static field with a certain name, etc.. Reflection is about handling language level structure. I met the best example of its usage in minecraft server code, which instead of using interfaces for event listeners each, use one interface "Listener" and upon its registration the code rolls through the methods of the class, finds those signed with the @EventHandler annotation, and recognizes the event to handle by the type of the only one parameter of that method. And, it works quite well. I can write you some code too, if you want.
11th Mar 2017, 11:36 PM
Magyar Dávid
Magyar Dávid - avatar
+ 1
The minecraft code is a mess to find anything in place and in one view, so I wrote my own code for ya. Give a like, if like it: https://code.sololearn.com/cZArftXSptQF/#java I used HashMap for the event handler list groups for each class, however, the minecraft code makes it one step further into complexity. Well, this is a way more user-friend code :) Feel free to ask.
16th Mar 2017, 9:26 PM
Magyar Dávid
Magyar Dávid - avatar