This week's book giveaway is in the Spring forum.
We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line!
See this thread for details.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Java Reflection

 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the advantage and disadvantage of using Reflecton ane when exactly should we use it.
Regards,
aakash
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi aakash,
i've some points in mind.
i'd assume that u already know reflection but strive to figure out its significance.
1. reflection is a heavy thing to use in the sense that we have to go through many things to invoke even a simple method on an object.
2. usually we don't need in our application code.
3. we need reflection when we want to build an application that will be dealing with classes that can be defined by the end user who uses the application and our application needs to know things about those classes.
e.g.
A) Java BeanBox- BeanBox uses reflection to know things about the Bean and uses it to display information in the Property Sheet etc..
B) Third party applications like "Rule Engine" which needs to allow loading/importing of the user defined classes so that the "Rule Engine" application can be used to define further "Rules" on "our" objects (this might be difficult to grasp as there is a new term "Rule Engine" but that is just an example. it can be any third party application that needs to import/load classes defined by us and allow us to do something more to those classes via that application)
C) what will you do to build a tool that can import any classes and then create a object model diagram from it? we can use reflection to know information about classes and prepare the model. though i don't know issues in this application.
the above 2 kinds are the biggest application of reflection i would say.
also, think how would you know methods/variables in some classes if you were not given any javadoc, api , java source files and you just have .class files which are not obfuscated? of course, we need to use reflection to know methods etc in the classes.

regards
maulin
 
reply
    Bookmark Topic Watch Topic
  • New Topic