Exceptions and lambda.

Srikanth S Adayapalam srikanth_sankaran at in.ibm.com
Wed Feb 6 01:28:57 PST 2013


> From: Srikanth S Adayapalam/India/IBM at IBMIN

> So, should I expect the following to fail to compile ? It compiles 
> fine with b74: 
> 
> // ---- 
> interface G1 { 
>    <E extends Exception> Object m(E p) throws E; 
>  } 
>  interface G2 { 
>    <F extends Exception> String m(F q) throws Exception; 
>  } 
>  interface G extends G1, G2 {} 
> 
>  // G has descriptor <F extends Exception> ()->String throws F 
> 
>  public class X { 
> 
>          G g = (x) -> { 
>                  return "OK"; 
>          }; 
>  } 
> // ---

Playing around with it a bit more I see that javac does reject a
program that tries to target a generic method, but not consistently:

import java.util.List;
interface A { <T> T foo(List<T> p); }
interface B { <S> S foo(List<S> p); }
interface C extends A, B {}

class Z {
    A a              =    (p) -> { return null;};  // rejected
    B d              =    (p) -> { return null;};  // rejected
    C c              =    (p) -> { return null;};  // accepted
}

I get a "method <T>(List<T>)T in interface A is generic" diagnostic.
So shouldn't 
    C c              =    (p) -> { return null;};  // accepted
also be rejected for the same reason ? 

Thanks!
Srikanth.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-spec-experts/attachments/20130206/c17f30f9/attachment-0001.html 


More information about the lambda-spec-experts mailing list