I'm interested in understanding why, in the example given below, the row instantiating wrapper2
gives a compilation error:
java: incompatible types: inference variable V has incompatible bounds
equality constraints: java.util.stream.Stream<EntityVersion<? extends BaseEntity>>
lower bounds: java.util.stream.Stream<EntityVersion<Product>>
Example:
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.val;
@Data
class BaseEntity {
UUID id;
}
@Data
@AllArgsConstructor
class Product extends BaseEntity {
String name;
};
@Data
@AllArgsConstructor
class EntityVersion<T extends BaseEntity> {
String status;
T entity;
}
record EntityVersions(Map<String, Stream<EntityVersion<? extends BaseEntity>>> entityVersions) {}
class Main {
public static void main(String[]args){
EntityVersion<Product> product = new EntityVersion<>("new", new Product("Product 1"));
Stream<EntityVersion<? extends BaseEntity>> products1 = Stream.of(product);
val wrapper1 = new EntityVersions(Map.of("products", products1));
Stream<EntityVersion<Product>> products2 = Stream.of(product);
val wrapper2 = new EntityVersions(Map.of("products", products2));
}
}