Created
October 24, 2019 04:24
-
-
Save sovannarithcheav/0a2578de3f2d89b34757dccb5d1c045e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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