Reputation: 7647
I have read a some interview questions on java and i found below.
Qus. Is It Good to use Reflection in an application ? Ans. No, It's like challenging the design of application
I need to clarify the above answer more as I learn reflection is a powerful feature of Java.
What is meant by challenging the design?
What scenario we have to practically use reflection in an application?
Upvotes: 2
Views: 64
Reputation: 2443
Challenging the design means you can:
java.lang.System
using reflection which you are not intended to. Though reflection is useful in certain cases:
FXML
, your interpreter dynamically loads the FXML
file and sets attributes to your nodes dynamically. using reflection. If you have ever programmed for android, you must know that programmers design the view
of their apps using .xml
files. Even in this case, your widgets are loaded dynamically using reflection. Basic example, in android:
<Button ...
android:onClick="callMe" />
Then you write the callMe(View view)
method in the .java
file. This listener is added to the button using reflection.
So there are both pros and cons of reflection.
You might want to refer this for further information
Upvotes: 1