Why aren't Enumerations Iterable?

后端 未结 5 1818
隐瞒了意图╮
隐瞒了意图╮ 2020-12-06 09:07

In Java 5 and above you have the foreach loop, which works magically on anything that implements Iterable:

for (Object o : list) {
  doStuff(o);         


        
5条回答
  •  长情又很酷
    2020-12-06 09:22

    Enumeration hasn't been modified to support Iterable because it's an interface not a concrete class (like Vector, which was modifed to support the Collections interface).

    If Enumeration was changed to support Iterable it would break a bunch of people's code.

提交回复
热议问题