首页 > 其他 > 详细

查询创建多少个对象

时间:2015-10-17 23:21:06      阅读:257      评论:0      收藏:0      [点我收藏+]

public class Test {
    public int id;
    public String name;
    private static long count;
    @SuppressWarnings("rawtypes")
    private final static ThreadLocal tl=new ThreadLocal();

    @SuppressWarnings("unchecked")
    public Test() {
    super();
    count++;
    tl.set(count);
 }
    public long getCount(){
    return (Long)tl.get();
 }
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
        Test t=new Test();
        System.out.println(t.getCount());
 }
}

}

输出

1
2
3

查询创建多少个对象

原文:http://www.cnblogs.com/96ZYJ/p/4888380.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!