Java: Out with the Old, In with the New

后端 未结 30 2026
遥遥无期
遥遥无期 2020-12-22 16:11

Java is nearing version 7. It occurs to me that there must be plenty of textbooks and training manuals kicking around that teach methods based on older versions of Java, whe

30条回答
  •  不思量自难忘°
    2020-12-22 16:24

    Generics and no longer needing to create an iterator to go through all elements in a collection. The new version is much better, easier to use, and easier to understand.

    EDIT:

    Before:

    List l = someList;
    Iterator i = l.getIterator();
    while (i.hasNext()) {
        MyObject o = (MyObject)i.next();
    }
    

    After

    List l = someList;
    for (MyObject o : l) {
        //do something
    }
    

提交回复
热议问题