Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.reflect.*;
- public class LogClass{
- public void log(){
- Field[] fields = this.getClass().getDeclaredFields();
- for(int i = 0; i< fields.length;i++){
- fields[i].setAccessible(true);
- try{
- System.out.println("[" + this.getClass().getName() + "]: " + fields[i].getName() + " = " + String.valueOf(fields[i].get(this)));
- }
- catch(Exception e){
- System.out.println("[" + this.getClass().getName() + "]: Could not get the value of." + fields[i].getName() + ". Exception thrown: " + e.toString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment