Skip to content

Instantly share code, notes, and snippets.

View techindepth's full-sized avatar
👋

ANISH ANTONY techindepth

👋
View GitHub Profile
Foo foo = parameter -> buildString(parameter);
private String buildString(String parameter) {
String result = "Something " + parameter;
//many lines of code
return result;
}
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("");
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 ");
Foo fooByIC = new Foo() {
@Override
public String method(String string) {
return string + " from Foo";
}
};
@FunctionalInterface
public interface FooExtended extends Baz, Bar {}
@FunctionalInterface
public interface Baz {
String method();
default void defaultBaz() {}
}
@FunctionalInterface
@FunctionalInterface
public interface Foo {
String method();
default void defaultMethod() {}
}
public interface Foo {
String method();
}
@FunctionalInterface
public interface Foo {
String method();
}
// 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);
// 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);
}
}