Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • When writing Java, remember it is not flexible. You, as the programmer, should be one to show flexibility. Then, cheat. For example, if you have control on the generated iterator, make a class which implements Iterator and Iterable. Delegate or inherit the methods of Iterator and do

    public Iterator iterator() {
        return this;
    }

    Prety stupid, but it may work. For Enumerations, you'll have to write an adapter from enumerations to iterations (if you can't find one in the forest of classes availabl

    • When writing Java, remember it is not flexible.

      Don't worry; I've never forgotten this. :)

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers
  • At least for an enumeration you can do:

    for ( Foo f : Collections.list( enumeration ) ) {
       ...
    }

    I suspect that, despite how much sense it makes, they didn't make the Iterator interface extend Iterable because it would break compatibility with a ton of custom Iterators people have coded in the years since Java 1.2. Java is extremely wary of doing this, even when doing differently (like with generics) winds up causing people pain for years.

    As it is, it's pretty easy to create a wrapper class to do

    • Collections.list( enumeration )

      Awesome! That is the glue I searched for in vain yesterday. Unfortunately it's too late for this particular project, but you can never have too much glue lying around for future tasks. :)

      --
      J. David works really hard, has a passion for writing good software, and knows many of the world's best Perl programmers