+ 3

What is reflection api in Java

what is the use of reflection api in java.. can anybody explains.. thanks

26th Apr 2017, 9:46 AM
Sbk0103
Sbk0103 - avatar
1 ответ
+ 8
Reflection help you to analys the classes an the member of the classes created by the other programmers also To know what are the member's(methods,constructers an other Declared fields etc) are present in it But this also reduce's the security of the programs as other can Know about your code which is a security threat for programmer's Example : public class Reflection { public static void main() { try { Class cls = Class.forName("any_class_name"); Field [] f = cls.getDeclaredFields(); System.out.println(f[0]); Method [] m = cls.getDeclaredMethods (); System.out.println(m[0]); Constructor [] c = cls.getDeclaredConstructors (); System.out.println(c[0]); } catch (ClassNotFoundException e) { System.out.println(e); } } } this may help you : http://docs.oracle.com/javase/tutorial/reflect/index.html
26th Apr 2017, 12:27 PM
Gings
Gings - avatar