打印实体类的属性和值

public class A{
      private String pa;
      public void setPa(String pa){
         this.pa = pa;
      }

      public void getPa(){
         return pa;
      }
      public String toString(){
    	String s = "\n----------------------------------------\n";
    	Class cls = this.getClass();
    	Field[] field = cls.getDeclaredFields();
    	System.out.println();
    	for(Field f : field){
    		try {
				System.out.println(f.getName()+"  =  "+f.get(this));
			} catch (IllegalArgumentException e) {				
				e.printStackTrace();
			} catch (IllegalAccessException e) {				
				e.printStackTrace();
			}
    	}      	    	
    	return s;
    }

}

你可能感兴趣的:(F#)