Lambda target type

This blog of Maurice Naftalin is a great place to learn lambda expression e.g

x -> 2 * x 

How does Java know which functional interface it is implementing? that information is deduced from the context. That context can be mentioned in the returnType which is known as the target type of a lambda expression

IntOperation iop = x -> x * 2; 

would be a lambda for

interface IntOperation { int operate(int i); } 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with
Get started
%d bloggers like this: