0

isTraversableAgain is declared final in GenTraversableLike and with its plethora of Known Subclasses, I would like to know the usage of the function and the wisdom behind its being final.

1 Answer 1

7

That method is defined on GenTraversableOnce, which is kind of a father to everything. Among that everything is Iterator, which can only be traversed once, and everything else, which is expected to be traversable multiple times. Though, of course, you can go up to GenTraversableOnce or TraversableOnce and subclass it with something else that is only traversable once.

The methods declared on GenTraversableLike rely on being able to traverse a collection multiple times.

3
  • ah... I trace isTraversableAgain from List and get to GenTraversableLike through linearization and miss the original source GenTraversableOnce. Thanks Daniel. Jan 3, 2012 at 20:11
  • The fact that it is a method implies that you might want to call it at runtime and make a decision about how to handle the collection based on the result. I'm having trouble imagining what situation that would be though I guess it is not impossible.
    – Owen
    Jan 3, 2012 at 21:48
  • 1
    @Owen grep? The method toArray uses it to decide whether to copy the whole collection to an intermediate collection first (if false), or call size to initialize the array and then copy the collection. Jan 4, 2012 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.