204.
a.
public interface Interface1 {
public void doSomething();
}
public interface Interface2 extends Interface1{
public void doSomethingElse();
}
Answer:
The code above declares a
functional interface called
Interface1 with an abstract method called doSomething. It
then defines another functional interface called Interface2 that
extends Interface1 and has and abstract method called
doSomethingElse. This code is perfectly valid. Interface2
now has two abstract methods, doSomething() and
doSomethingElse(). Since
it is not marked with the
@FunctionalInterface annotation, it is okay to have multiple
abstract methods. Had the @FunctionalInterface annotation
been used on Interface2, the code would have caused a
compilation error.
Name some pre–Java 8 interfaces that are made
functional interfaces by Java 8.
Answer:
Prior to Java 8, there are some interfaces that already had a
single abstract method. Java 8 has designated these interfaces
as functional
interfaces by specifying the
@FunctionalInterface annotation on them. So, the abstract
methods in these interfaces can be implemented via lambda
expressions. These interfaces are as follows:
java.lang.Runnable:
Used to create a Thread
b.
c.
d.
205.
java.util.cocurrent.Callable: Used to create a Thread that
returns a value
java.util.Comparator:
Used to compare values
java.io.FileFilter: Used to filter Files
Why are primitive specializations of the in–built functional
interfaces like IntSupplier, BooleanSupplier, etc. added by
Do'stlaringiz bilan baham: