This code seems logical to me, why the compiler is complaining about the predicate isBondAsset having the wrong type ?
I mean a "Predicate of any type that extends Asset" is a "Predicate of any type super of any type that extends Asset" or i'm wrong ?
private static class Asset
{
public enum AssetType
{
BOND,
STOCK;
}
private final AssetType type;
private final int value;
public Asset (AssetType type, int value)
{
this.type = type;
this.value = value;
}
public AssetType getType ()
{
return type;
}
public int getValue ()
{
return value;
}
}
private static class AssetUtils
{
public static int totalBondAssetValues (Collection <? extends Asset> assets)
{
Predicate<? extends Asset> isBondAsset = asset -> Asset.AssetType.BOND.equals(asset.getType());
return assets.stream().filter(isBondAsset).mapToInt(Asset::getValue).sum();
}
}