Java - Lambdas: Difference between revisions
From My Limbic Wiki
(Page créée avec « =Questions & Answers= concrete methods interface methode default implementee = interface fonctionnelle * if a class implements two interfaces with the same name method:... ») |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Lambdas= | |||
==Syntax== | |||
<source lang="java"> | |||
(String first, String second) -> Integer.compare(first.length(), second.length()) | |||
</source> | |||
==Functional Interfaces== | |||
===Declaration=== | |||
Runnable has a functional interface wich has exactly one abstract method | |||
<source lang="java"> | |||
Runnable runner = () -> { ...; System.out.println(this.toString()); ... }; | |||
(String first, String second) -> { | |||
if (first.length() < second.length()) return -1; | |||
else if (first.length() > second.length()) return 1; | |||
else return 0; | |||
} | |||
</source> | |||
===Use=== | |||
<source lang="java"> | |||
Arrays.sort(strings, String::compareToIgnoreCase) | |||
</source> | |||
==Use== | |||
Use Functional Interfaces https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html They have only one method | |||
=Questions & Answers= | =Questions & Answers= |
Latest revision as of 15:57, 18 October 2019
Lambdas
Syntax
<source lang="java">
(String first, String second) -> Integer.compare(first.length(), second.length())
</source>
Functional Interfaces
Declaration
Runnable has a functional interface wich has exactly one abstract method <source lang="java">
Runnable runner = () -> { ...; System.out.println(this.toString()); ... };
(String first, String second) -> {
if (first.length() < second.length()) return -1; else if (first.length() > second.length()) return 1; else return 0;
} </source>
Use
<source lang="java"> Arrays.sort(strings, String::compareToIgnoreCase) </source>
Use
Use Functional Interfaces https://docs.oracle.com/javase/8/docs/api/java/lang/FunctionalInterface.html They have only one method
Questions & Answers
concrete methods interface methode default implementee = interface fonctionnelle
- if a class implements two interfaces with the same name method: multiplicatedefaulterror
je ne peux utiliser que les variables finales dans une lambda expression lambda n'est pas thread safe
Loops
INTERNAL: nouveau foreach ==> je ne veux pas savoir ce ton implementation: fais le avec la lambda que je te donne EXTERNAL: ancien foreach, a BANNIR