Basics of Java Reflection Attributes - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

Basics of Java Reflection Attributes

Share This

To get details of the fields declared in a class, and details of annotations, reflection can be used. Using reflection, current values of the fields can be retrieved and new values can be set.
Content of TestMain.java
package com.t4b.test; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; public class TestMain { static Class<?> c; public static void main(String[] args) { try { c = Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } System.out.println("Fields:"); for (Field field : c.getDeclaredFields()) { System.out.println(field.getName()); System.out.println(field.getType()); } } }

Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.