Advertisement
JoshuaStrutt

LogClass

Feb 19th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. import java.lang.reflect.*;
  2. public class LogClass{
  3.  
  4.   public void log(){
  5.     Field[] fields = this.getClass().getDeclaredFields();
  6.     for(int i = 0; i< fields.length;i++){
  7.       fields[i].setAccessible(true);
  8.       try{
  9.         System.out.println("[" + this.getClass().getName() + "]: " + fields[i].getName() + " = " + String.valueOf(fields[i].get(this)));
  10.       }
  11.       catch(Exception e){
  12.         System.out.println("[" + this.getClass().getName() + "]: Could not get the value of." + fields[i].getName() + ". Exception thrown: " + e.toString());
  13.       }
  14.     }
  15.   }
  16.  
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement