Difference between revisions of "Kava Lambda Expressions"

From MyWiki
Jump to: navigation, search
Line 5: Line 5:
 
}
 
}
 
</source>
 
</source>
Example1<br>
+
Example1 - Numeric test<br>
 
<source lang="java">
 
<source lang="java">
 
interface NumericTest {
 
interface NumericTest {

Revision as of 20:57, 10 April 2020

Functional Interface

interface MyName{
  String computeName(String str);
}

Example1 - Numeric test

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));
}