Java Scrap Book  

Java Scrap Book > Java Reflection > Get Class Variable

How to Class Variable Name Using Reflection

  1. java.lang.reflect.Field library contains function to get information about the class field
  2. object.getClass() function return object class name.

import java.lang.reflect.Field;

public class GetClass {
public static void main(String[] args) {
    Demo a=new Demo();
    Field[] field= a.getClass().getDeclaredFields();
    for( Field field1: field){
        System.out.println(field1.getName());
    }
  }
}

class Demo{
private int a;
private float b;
private String solve(){
return null;
}
public int getA(){
return this.a;
}
}


Copyright © 2013-2017

javascrapbook.com is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: javascrapbook2013@gmail.com