楼主把两种方法都说过了,应该没有方法了吧。
第一种就是通过对象直接获取类名 a.getClass().getName();
第二种就是通过反射获取对象然后获取类名 Class.forNmae("test.A").getName坐等大牛,等待其他方法。

解决方案 »

  1.   

    我以前在网上看见过这个方法。String clazz = Thread.currentThread().getStackTrace()[1].getClassName();亲测可用。
    基于 Java 1.7
      

  2.   

    补充一下,
    获取方法名String method = Thread.currentThread().getStackTrace()[1].getMethodName();基于 Java 1.7 
      

  3.   

    在网上找到这个链接,你可以看看。
    http://hi.baidu.com/kittopang/item/a04c9ed12ff32aefb2f77711
      

  4.   

    public static void main(String[] args) throws Exception { System.out.println(new Throwable().getStackTrace()[0].getClassName());
    }
      

  5.   

    System.out.println(Thread.currentThread().getStackTrace()[1].getClassName());