vigna / fastutil

fastutil extends the Javaâ„¢ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.78k stars 196 forks source link

Make forEachTYPE instead of overloading forEach for primitive collections #186

Closed techsy730 closed 3 years ago

techsy730 commented 3 years ago

Rename the forEach(TYPEConsumer) methods to forEachTYPE(TYPEConsumer) for primitive TYPEs.

This solves an ambiguity when calling forEach with a lambda requiring casting the lambda to solve. By happenstance it wasn't an issue for int, long, and double collections due to Fastutil's consumer being both an object and primitive consumer, solving the ambiguity. However, it was an issue for byte, short, char, and float collections.

This also means we can remove the messy "don't override this" disambiguation overrides that int, long, and double Iterables had, and cleans up all the cruft associated with it.

Note this only fixes it for type specific Iterables, not for the Spliterators. However, as Spliterators are rarely used "raw", this isn't as big of an issue. Perhaps can be a future cleanup.

vigna commented 3 years ago

@techsy730 I'm in awe by the speed and precision with which you code, but can we talk before you write hundreds of line of code? 😂 You totally convinced me there was no need for this. LOL.

vigna commented 3 years ago

So, I checked every possible case I could think of: I must conclude that the warning from javac is wrong. No matter what I did—lambdas, variables—I could not create an ambiguous call (in Eclipse—in the past, I had the two compilers diverge).

Moreover, the ambiguity reported is between two deprecated methods. So basically we won't really care.

I'd leave your code as it is—you already did the right thing.