Код: Выделить всё
interface Fruit
{
public List getColors();
public List getChildren();
}
class FruitUtil
{
public static void readFruit(Fruit fruit)
{
for(String color : fruit.getColors()) // shows error : Type mismatch: cannot convert from element type Object to String
{
}
for(Fruit thisFruit : fruit.getChildren()) // shows error : Type mismatch: cannot convert from element type Object to Fruit
{
}
}
}
Но при использовании метода getColors() для фруктов он возвращает «Список» вместо «Список строк», несмотря на то, что он имеет точный тип возвращаемого значения.
Я Я что-то здесь пропустил?
Подробнее здесь: https://stackoverflow.com/questions/790 ... ic-in-java
Мобильная версия