Java反射获取实例的速度对比-创新互联

本篇文章给大家分享的是有关Java反射获取实例的速度对比,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

创新互联建站专业为企业提供诸城网站建设、诸城做网站、诸城网站设计、诸城网站制作等企业网站建设、网页设计与制作、诸城企业网站模板建站服务,10年诸城做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
  public static void main(String[] args) {
    try {
      int MAX = 100000;
      for (int count = 0; count < 50; count++) {
        System.out.println("====第" + count+"次");
 
        long s1 = System.currentTimeMillis();
        for (int i = 0; i < MAX; i++) {
          Person o = (Person)Class.forName("com.qingtai.domin.Person").newInstance();
        }
        long e1 = System.currentTimeMillis();
        System.out.println("1_duration:" + (e1 - s1));
 
        long s2 = System.currentTimeMillis();
        Class clazz = Class.forName("com.qingtai.domin.Person");
        for (int i = 0; i < MAX; i++) {
          Person person = (Person) clazz.newInstance();
        }
        long e2 = System.currentTimeMillis();
        System.out.println("2_duration:" + (e2 - s2));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

文章题目:Java反射获取实例的速度对比-创新互联
浏览路径:http://myzitong.com/article/deogeh.html