Difference between revisions of "Kava Lambda Expressions"
From MyWiki
(Created page with "Functional Interface<br> <source lang="java"> interface MyName{ String computeName(String str); } </source>") |
|||
Line 3: | Line 3: | ||
interface MyName{ | interface MyName{ | ||
String computeName(String str); | String computeName(String str); | ||
+ | } | ||
+ | </source> | ||
+ | Example1<br> | ||
+ | <source lang="java"> | ||
+ | interface NumericTest { | ||
+ | boolean computeTest(int n); | ||
+ | } | ||
+ | |||
+ | public static void main(String args[]) { | ||
+ | NumericTest isEven = (n) -> (n % 2) == 0; | ||
+ | NumericTest isNegative = (n) -> (n < 0); | ||
+ | |||
+ | // Output: false | ||
+ | System.out.println(isEven.computeTest(5)); | ||
+ | |||
+ | // Output: true | ||
+ | System.out.println(isNegative.computeTest(-5)); | ||
} | } | ||
</source> | </source> |
Revision as of 20:56, 10 April 2020
Functional Interface
interface MyName{ String computeName(String str); }
Example1
interface NumericTest { boolean computeTest(int n); } public static void main(String args[]) { NumericTest isEven = (n) -> (n % 2) == 0; NumericTest isNegative = (n) -> (n < 0); // Output: false System.out.println(isEven.computeTest(5)); // Output: true System.out.println(isNegative.computeTest(-5)); }