Additional method on Stream

Remi Forax forax at
Sat May 2 14:41:31 UTC 2015

On 04/28/2015 03:05 PM, Paul Sandoz wrote:


>> I do understand the desire to control methods, but API design isn't
>> just about minimalism, it is also about meeting common use cases in a
>> natural way. The parallel is of course a standard if (obj instanceof
>> Foo) statement in Java, where developers often curse that they have to
>> additionally cast obj after the check.
> I believe Ceylon might also do contextual type narrowing. I dunno how easy it would to modify the Java language and javac to do similar things. A separate discussion to be had...

I think this was discussed on the coin project mailing list when talking 
about the precise re-throw of exception.
The main issue is that a more precise type will select another overload 
than the one that javac currently select:

class A {}
class B extends A {}
class Bar {
   void foo(A a) { ... }
   void foo(B b) { ... }

Let suppose we have this code:
   A a = ...
   if (a instanceof B) {

without narrowing, it will call foo(A), with narrowing, it will call foo(B).


More information about the core-libs-dev mailing list