我有一个扩展另一个类的类:
public class PDFCrawler extends WebCrawler
我正在重写我的 PDFCrawler 类中的一个方法,如下所示:
@Override
public boolean shouldVisit(Page page, WebURL url) {...}
它在 Eclipse 上给我错误。为项目设置了 Java 8:
The method shouldVisit(Page, WebURL) of type PDFCrawler must override or implement supertype method.
但是,在同一个 PDFCrawler 类中,当我如下覆盖不同的方法时,没有显示错误:
@Override
public void visit(Page page) {...}
这两个方法都来自名为 WebCrawler 的父类(super class)。父类(super class)方法如下:
public boolean shouldVisit(Page page, WebURL url) {
return true;
}
public void visit(Page page) {
// Do nothing by default
// Sub-classed should override this to add their custom functionality
}
父类(super class)取自Crawler4j project .由于我无法重写第一个方法,因此始终会执行父类(super class)中的方法。
有什么线索吗?
编辑 我的类 PDFCrawler 的导入语句:
package com.example.ict;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import java.util.regex.Pattern;
import com.google.common.io.Files;
import edu.uci.ics.crawler4j.crawler.Page;
import edu.uci.ics.crawler4j.crawler.WebCrawler;
import edu.uci.ics.crawler4j.url.WebURL;
最佳答案
我猜您正在使用旧版本的 crawler4j 中的 jar 文件。此方法的签名在过去有所不同,并且在不支持向后兼容的情况下进行了更改(不幸的是):https://github.com/yasserg/crawler4j/commit/c874761011d63e77977b914810eb44c054845233
使用最新版本的 jar 应该可以解决问题。
关于java - 为什么我不能使用 Override 注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29526357/