Tag: Java

  • Java File API

    I don’t like Java’s File API. It’s main problem is that is mixes several responsibilities into one class. One responsibility is handling of “abstract” file and path names, i.e. operating system independent file names. The other responsibilities are all file system related: Querying file meta information (access rights, access times, file type), creating files, and listing…

  • Java: Iterators are not Iterable

    This is something I stumbled across multiple times now in Java: Iterators are not Iterable. Java 1.5 introduced the foreach statement, which allows easy iteration over collections like this: for (MyClass item: myCollection) { doStuffWithItem(item); } For this to work class MyClass must implement the Iterable interface. This interface defines just one method that returns an Iterator: Iterator<T> iterator(); This works fine in many cases.…