Я получаю приведенную ниже ошибку для кода Java 8, разработанного ниже.В этом примере мы пытаемся объединить все имена Блюда в одну переменную.С кодом ниже я получил это "The method collect(Collector<? super Dish,A,R>) in the type Stream<Dish> is not applicable for the arguments (Collector<CharSequence,capture#3-of ?,String>)"
.
Dish.java
@Builder
@Data
@AllArgsConstructor
public class Dish {
public enum Type { MEAT, FISH, OTHER }
private final String name;
private final boolean vegetarian;
private final int calories;
private final Type type;
public static final List<Dish> menu =
Arrays.asList( new Dish("pork", false, 800, Dish.Type.MEAT),
new Dish("beef", false, 700, Dish.Type.MEAT),
new Dish("chicken", false, 400, Dish.Type.MEAT),
new Dish("french fries", true, 530, Dish.Type.OTHER),
new Dish("rice", true, 350, Dish.Type.OTHER),
new Dish("season fruit", true, 120, Dish.Type.OTHER),
new Dish("pizza", true, 550, Dish.Type.OTHER),
new Dish("prawns", false, 400, Dish.Type.FISH),
new Dish("salmon", false, 450, Dish.Type.FISH));
}
Вот основной метод
String shortMenu = Dish.menu.stream().map(Dish::getName).collect(joining());
System.out.println(shortMenu);
String shortMenu1 = Dish.menu.stream().collect(joining()); //line-3