I have an 'Animal' interface and 'Dog' class that implements 'Animal'.
public interface Animal {
void makeVoice();
}
public class Dog implements Animal {
@Override
public void makeVoice() {
System.out.println("aou aou");
}
}
In my main method, I wrote the following lines.
public class Main {
public static void main(String[] args) {
Animal dog = Dog::new; // How is it compiled? it should be Supplier<Animal>
dog.makeVoice(); // Doesn't call because 'dog' holds lambda expression (Supplier<Animal>) and not the actual 'Dog' class.
}
}
Why is it possible that Animal can hold Supplier?
I expected that it doesn't compile.