请写出一段java代码.要求:
1这个代码在jdk1.5下能编译通过
2代码只要是在jdk1.5的版本,无论外界是何种情况运行结果都一样
3代码只要是在jdk1.6的版本,无论外界是何种情况运行结果都一样
4在jdk1.5的状态下和在jdk1.6的状态下运行结果不一样

解决方案 »

  1.   

    System.out.println(System.getProperty("java.specification.version"));
      

  2.   

    再来一个
        try {
          Class.forName("java.awt.SystemTray");
          System.out.println("1.6");
        } catch (ClassNotFoundException ex) {
          System.out.println("1.5");
        }
      

  3.   

    java 6 的变化:运行结果 java 5/6 不一样。
      

  4.   

    不符合
    2代码只要是在jdk1.5的版本,无论外界是何种情况运行结果都一样
    3代码只要是在jdk1.6的版本,无论外界是何种情况运行结果都一样
      

  5.   

    System.out.println(LinkedList.class.getInterfaces().length);
    LinkedList - retrofitted to implement the Deque interface.
    http://download.oracle.com/javase/6/docs/technotes/guides/collections/changes6.htmlhttp://www.oracle.com/technetwork/java/javase/adoptionguide-137484.html
    http://www.oracle.com/technetwork/java/javase/features-141434.html
      

  6.   

    上面说的不符合,应是不符合2,JDK1.5 Windows和JDK Linux运行效果可能不同
      

  7.   

    只要是添加了新方法的类 AnyClass.class.getMethods() 在 5/6 结果肯定不一样。
      

  8.   

    晕。这个jre不同结果不同。不符合要求
      

  9.   

    These new collection interfaces are provided:
    Deque - a double ended queue, supporting element insertion and removal at both ends. Extends the Queue interface.