Lambda Expression + Requirements to Java Classes and Interfaces

maurizio cimadamore maurizio.cimadamore at oracle.com
Sun Dec 5 03:54:59 PST 2010


On 05/12/2010 11:07, Felix Schmidt wrote:
> Everybody:
>
> I want to explore the benefits of lambda expressions for our open source
> software.
>
> Here are some questions:
> 1. What are the basic requirements to a java object?
>
> If I have such a abstract class
>
> public abstract class AbstractClass {
>     public void testMethod() {
>        // do something here
>     }
>     public abstract void abstractMethod();
> }
>
> Is it possible to do something like:
> AbstractClass class = #{System.out.println("abstract class")};
>
> Or if this syntax is not valid, how could I modify either the
> AbstractClass or the instantiation?
The syntax is correct - the lambda expression you typed will be used as 
iplementation for the abstract method AbstractClass.testMethod(). After 
this conversion (aka 'SAM conversion') you will be able to use the 
instance of 'AbstractClass' created this way, as if it were an ordinary 
Java instance (i.e. created through anonymous inner class creation 
expression). WHich means you will be able to call both testMethod() and 
abstractMethod() [the latter call wille execute the code inside the lambda].

Thanks
Maurizio
> Thank you
> felix
>



More information about the lambda-dev mailing list