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
| Foo foo = parameter -> buildString(parameter); | |
| private String buildString(String parameter) { | |
| String result = "Something " + parameter; | |
| //many lines of code | |
| return result; | |
| } |
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
| public String scopeExperiment() { | |
| Foo fooIC = new Foo() { | |
| String value = "Inner class value"; | |
| @Override | |
| public String method(String string) { | |
| return this.value; | |
| } | |
| }; | |
| String resultIC = fooIC.method(""); |
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
| public interface Adder { | |
| String add(Function<String, String> f); | |
| void add(Consumer<Integer> f); | |
| } | |
| public class AdderImpl implements Adder { | |
| @Override | |
| public String add(Function<String, String> f) { | |
| return f.apply("Something "); |
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
| Foo fooByIC = new Foo() { | |
| @Override | |
| public String method(String string) { | |
| return string + " from Foo"; | |
| } | |
| }; |
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
| @FunctionalInterface | |
| public interface FooExtended extends Baz, Bar {} | |
| @FunctionalInterface | |
| public interface Baz { | |
| String method(); | |
| default void defaultBaz() {} | |
| } | |
| @FunctionalInterface |
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
| @FunctionalInterface | |
| public interface Foo { | |
| String method(); | |
| default void defaultMethod() {} | |
| } |
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
| public interface Foo { | |
| String method(); | |
| } |
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
| @FunctionalInterface | |
| public interface Foo { | |
| String method(); | |
| } |
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 with Optional Class | |
| import java.util.Optional; | |
| public class OptionalDemo{ | |
| public static void main(String[] args) { | |
| String[] words = new String[10]; | |
| Optional<String> checkNull = | |
| Optional.ofNullable(words[5]); | |
| if (checkNull.isPresent()) { | |
| String word = words[5].toLowerCase(); | |
| System.out.print(word); |
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 without Optional Class | |
| public class OptionalDemo{ | |
| public static void main(String[] args) { | |
| String[] words = new String[10]; | |
| String word = words[5].toLowerCase(); | |
| System.out.print(word); | |
| } | |
| } |