I think two examples will explain it, first what you wanted was a supplier for a meaningful string to print. Like,
Supplier<String> newString = () -> "test";
System.out.println(newString.get());
What you provided was an empty string. Like,
System.out.println(new String());
It's perfectly valid to produce an empty string, even if the result deviated from your expectations.
Bonus third example, to elaborate on the first example, in a lambda expression you are actually implementing a single abstract method from a functional interface - specifically Supplier<T>
. Like,
Supplier<String> newString = new Supplier<String>() {
@Override
public String get() {
return "test"; // originally return new String()
}
};
System.out.println(newString.get());