Functional Interface Supplier - Quiz
Total: 2 questions
1. When the Supplier interface can be used?
When the Supplier interface can be used?
The Supplier can be used in cases when there is no input but an output is expected.
2. Write example of usage Supplier interface, which just return an instance of some object.
Write example of usage Supplier interface, which just return an instance of some object.
public class Animal {
public void move() {
System.out.println("Move");
}
@Override
public String toString() {
return "Some Animal";
}
}
public class TestAnimal {
public static void main(String args[]) {
Supplier<Animal> s = () -> new Animal();
System.out.println(s.get());
}
}
Page 1 of 1