我正在为Web开发人员使用Eclipse Java EE IDE。
版本:Helios Service Release 2 建造ID:20110218-0911
目前我正在编写一个书店项目,但是在编译ShoppingCart.java时,它会显示
“ - java.util.function.Consumer类型无法解析。它是从必需的.class间接引用的 文件
- The type java.util.function.Consumer cannot be resolved. It is indirectly referenced from required .class
files
- The type java.util.function.Predicate cannot be resolved. It is indirectly referenced from required .class files
- The type java.util.function.UnaryOperator cannot be resolved. It is indirectly referenced from
required .class files
- The type java.util.Comparator cannot be resolved. It is indirectly referenced from required .class files"
一开始。 这是Book.java
package bookstore;
import java.io.Serializable;
public class Book implements Serializable {
private static final long serialVersionUID = 1L;
private String isbn;
private String author;
private String title;
private double price;
private int edition;
private String publisher;
private String copyright;
public Book(String isbn, String author, String title, double price, int edition, String publisher, String copyright) {
this.isbn = isbn;
this.author = author;
this.title = title;
this.price = price;
this.edition = edition;
this.publisher = publisher;
this.copyright = copyright;
}
public String getIsbn() {
return isbn;
}
public String getAuthor() {
return author;
}
public int getEdition() {
return edition;
}
public String getPublisher() {
return publisher;
}
public String getCopyright() {
return copyright;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
和ShoppingCart.java
package bookstore;
import java.util.*;
import java.util.ArrayList;
public class ShoppingCart extends ArrayList<Book> {
private static final long serialVersionUID = 1L;
public ShoppingCart() {
}
public void addBook(Book book) {
this.add(book);
}
public Book getBook(int i) {
return this.get(i);
}
public double getTotalPrice() {
double price = 0.0;
for (Book book : this) {
price += book.getPrice();
}
return price;
}
}
我没有包含Consumer,Predicate,UnaryOperator和Comparator的功能。我发现问题可能是由于“extends ArrayList”
答案 0 :(得分:0)
这是一个令人烦恼的Eclipse Bug,似乎偶尔会咬人。见http://dev-answers.blogspot.de/2009/06/eclipse-build-errors-javalangobject.html
获取可能的解决方案,否则请尝试以下操作;
关闭项目并重新打开它。 清理项目(它将重建构建路径,从而使用JDK库重新配置)
OR
删除并重新导入项目,如有必要,请再次执行上述步骤。