Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
https://www.javatpoint.com/java-reflection 1/7
9/11/2017 Java Reflection - javatpoint
java.lang.Class class
The java.lang.Class class performs mainly two tasks:
Method Description
https://www.javatpoint.com/java-reflection 2/7
9/11/2017 Java Reflection - javatpoint
Let's see the simple example of forName() method.
1. class Simple{}
https://www.javatpoint.com/java-reflection 3/7
9/11/2017 Java Reflection - javatpoint
2.
3. class Test{
5. Class c=Class.forName("Simple");
6. System.out.println(c.getName());
7. }
8. }
Simple
It returns the instance of Class class. It should be used if you know the
type. Moreover, it can be used with primitives.
1. class Simple{}
2.
3. class Test{
5. Class c=obj.getClass();
6. System.out.println(c.getName());
7. }
10.
12. t.printName(s);
13. }
14. }
15.
Simple
3) The .class syntax
https://www.javatpoint.com/java-reflection 4/7
9/11/2017 Java Reflection - javatpoint
1. class Test{
3. Class c = boolean.class;
4. System.out.println(c.getName());
5.
6. Class c2 = Test.class;
7. System.out.println(c2.getName());
8. }
9. }
boolean
Test
Let's see the simple example of reflection api to determine the object
type.
1. class Simple{}
2. interface My{}
3.
4. class Test{
7. Class c=Class.forName("Simple");
https://www.javatpoint.com/java-reflection 5/7
9/11/2017 Java Reflection - javatpoint
8. System.out.println(c.isInterface());
9.
11. System.out.println(c2.isInterface());
12.
14.
15. }
16. }
false
true
newInstance() method
prev next
Please Share
Latest 4 Tutorials
DB2 MariaDB
ADO.NET ASP.NET
https://www.javatpoint.com/java-reflection 6/7
9/11/2017 Java Reflection - javatpoint
https://www.javatpoint.com/java-reflection 7/7