Java 8 Function - Incompatible Types

Viewed 769

I am attempting to assign a java 8 function pointer to a variable but get an incompatible type error when building. It appears that the compiler is not respecting "? extends BaseEntity".

For the below code ChildEntity directly extends BaseEntity:

private int getValue(ChildEntity entity) {
    return 0;
}

Function<? extends BaseEntity, ?> function = this::getValue;

Error: Base entity can not be converted to a ChildEntity.

4 Answers
Related