Exceptions and lambda.

Srikanth S Adayapalam srikanth_sankaran at in.ibm.com
Tue Feb 5 22:41:03 PST 2013

> From: Dan Smith <daniel.smith at oracle.com>
> Subject: Re: Exceptions and lambda.
> If you're getting an error from the lambda expression, that's the 
> expected behavior.  Perhaps the error message could be improved, 
> This is not actually an exception problem: we simply don't allow 
> lambda expressions to have type parameters.  There's no syntax to 
> introduce them, and if we inferred the declaration (something we 
> thought about), it would be impossible or very confusing to talk 
> about the type variable (e.g., give the lambda parameter an explicit 

I understand the part about there being no syntax to introduce type
variables, but with types elided and inferred, the snippet I posted
constitutes a well formed program as far I can see - we are working
with a particular instance of type that meets the bounds criteria
specified by the interface method and it is surprising that I cannot 
simply throw that object - I apologize if this was discussed earlier 
and I missed the discussion. 

> The implication is that the only way to instantiate a functional 
> interface that has a generic method (well, excluding the boring 
> approach of declaring a class) is to use a method reference.

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";
// ---
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/lambda-spec-experts/attachments/20130206/b7cf04db/attachment.html 

More information about the lambda-spec-experts mailing list