zoukankan      html  css  js  c++  java
  • 输出打印某个对象所有属性及属性值

    由于对象的属性值太多,又不想用Debug调试查看,自己还懒,于是上网搜搜,整理了一下代码

    package com.port.tools;

    import java.lang.reflect.Field;

    /**
     * @author gch
     * @date 2015-5-6
     *  @version 1.0
     *  辅助测试
     */
    public class PrintAllField {
     
     public static <T> T outprint(String s1,Object o ){
      try {
       Class<?> c =  Class.forName(s1);
             Field [] fields = c.getDeclaredFields(); 
             for(Field f:fields){ 
                 f.setAccessible(true); 
             } 
             System.out.println("============="+s1+"==============="); 
             for(Field f:fields){ 
                 String field = f.toString().substring(f.toString().lastIndexOf(".")+1);         //取出属性名称 
                 System.out.println(field+" --> "+f.get(o)); 
             }    
      } catch (ClassNotFoundException e) {
       e.printStackTrace();
      } catch (IllegalArgumentException e) {
       e.printStackTrace();
      } catch (IllegalAccessException e) {
       e.printStackTrace();
      }
      return null;
      
     }
     
    }

  • 相关阅读:
    187A Permutations
    DFS 专题 哈密顿绕行世界问题
    DFS 专题 N皇后
    DFS专题 Prime Ring Problem
    USACO section1.1 Broken Necklace
    USACO section1.2 Dual Palindromes
    PHPUnitWriting Tests for PHPUnit
    PHP 定界符 使用技巧
    concat函数
    mysql_free_result
  • 原文地址:https://www.cnblogs.com/llhl/p/9648741.html
Copyright © 2011-2022 走看看