Last active
May 10, 2018 00:16
-
-
Save lgsantiago/5bfa2f983b35fba62f3c8e3353cd5709 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
| interface MyGeneric<T> { | |
| T compute(T t); | |
| } | |
| public static void main(String args[]){ | |
| // String version of MyGenericInteface | |
| MyGeneric<String> reverse = (str) -> { | |
| String result = ""; | |
| for(int i = str.length()-1; i >= 0; i--) | |
| result += str.charAt(i); | |
| return result; | |
| }; | |
| // Integer version of MyGeneric | |
| MyGeneric<Integer> factorial = (Integer n) -> { | |
| int result = 1; | |
| for(int i=1; i <= n; i++) | |
| result = i * result; | |
| return result; | |
| }; | |
| // Output: omeD adbmaL | |
| System.out.println(reverse.compute("Lambda Demo")); | |
| // Output: 120 | |
| System.out.println(factorial.compute(5)); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is fixed. Thanks!