-1
我有以下方法:如何将变量传递给Java中的匿名内部类?
public Promise<List<SearchResult>> search(String searchTerms, SearchType type) {
Promise<List<SearchResult>> response = WS.url(type.url + searchTerms).
get().map(
new Function<WSResponse, List<SearchResult>>() {
public List<SearchResult> apply(WSResponse response) {
Document doc = Jsoup.parse(response.getBody());
Elements results = doc.select(type.selector);
return buildResultList(results);
}
}
);
return response;
}
不编译,因为匿名内部类没有访问SearchType
参数传递到search
方法。
我在想如何才能访问匿名类中的这个参数?
我写我的课程的方式是为每个SearchType
复制这种搜索方法 - 即我有三种不同的搜索方法(使用不同的名称),但我希望有一些代码重用,因此我试图重写方法,SearchType
参数被传入。
错误信息说什么?搜索它可能是值得的。 – user2864740 2014-09-27 06:17:05