Skip to content

Instantly share code, notes, and snippets.

@sovannarithcheav
Created October 24, 2019 04:24
Show Gist options
  • Select an option

  • Save sovannarithcheav/0a2578de3f2d89b34757dccb5d1c045e to your computer and use it in GitHub Desktop.

Select an option

Save sovannarithcheav/0a2578de3f2d89b34757dccb5d1c045e to your computer and use it in GitHub Desktop.
// Java program to demonstrate lamda expressions to implement
// a user defined functional interface.
@FunctionalInterface
interface Square
{
int calculate(int x);
}
class Test
{
public static void main(String args[])
{
int a = 5;
// lambda expression to define the calculate method
Square s = (int x)->x*x;
// parameter passed and return type must be
// same as defined in the prototype
int ans = s.calculate(a);
System.out.println(ans);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment