我正在尝试编译一位前同事的代码,但它说该方法unmodifiableList()不能应用于给定类型。Eclipse 中的代码没有显示任何错误。但它仍然不让我编译它。可能是什么错误?
package framework.interview.demographics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import framework.data.people.NonReference;
import framework.data.people.people;
public class schedualData {
private final List<people> schedual;
private schedualData(List<people> schedual) {
this.schedual = Objects.requireNonNull(schedual);
}
public static schedualData getSchedualData(List<people> schedual) {
if(schedual.size() < 1)
throw new IllegalArgumentException("schedual must contain at least one people");
if(Stream.of(schedual).filter(people -> (!(people instanceof NonReference))).count() != 1)
throw new IllegalArgumentException("There must be one and only one Reference between" + "People, number, and Review");
return new schedualData(schedual);
}
//****** Getters ******\\
public people getReference() {
return schedual.stream()
.filter(people -> !(people instanceof NonReference))
.toArray(people[]::new)[0];
}
public List<NonReference> getNonReferenceschedual() {
//This is where the error is showing.
return Collections
.unmodifiableList(schedual.stream()
.filter(NonReference.class::isInstance)
.map(x -> (NonReference) x)
.collect(Collectors.toCollection (ArrayList<NonReference>::new)));
}
public List<people> getFullschedual() {
return Collections.unmodifiableList(schedual);
}
public int size() {
return schedual.size();
}
}
千巷猫影
相关分类