我正在尝试建立一个系统,该系统允许我对导出到文本文件的类进行子类化,而无需修改初始类。为此,我正在尝试构建一个回调列表,可以判断它们是否处理特定条目,然后使用该回调获取从文件创建的该类的实例。问题是我得到一个错误
java.lang.NoClassDefFoundError: com/google/common/base/Predicate 当我尝试运行涉及此类的任何内容时。我究竟做错了什么?
public abstract class Visibility {
private static final List<VisibilityCreationCallback> creationCallbacks;
static {
creationCallbacks = new ArrayList<VisibilityCreationCallback>();
Reflections reflections = new Reflections(new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("com.protocase.viewer.utils.visibility"))
.setScanners(new ResourcesScanner()));
// ... cut ...
public static Visibility importFromFile(Map<String, Object> importMap) {
for (VisibilityCreationCallback callback: creationCallbacks) {
if (callback.handles(importMap)) {
return callback.create(importMap);
}
}
return null;
}
public class CategoryVisibility extends Visibility{
public static VisibilityCreationCallback makeVisibilityCreationCallback () {
return new VisibilityCreationCallback() {
@Override
public boolean handles(Map<String, Object> importMap) {
return importMap.containsKey(classTag);
}
@Override
public CategoryVisibility create(Map<String, Object> importMap) {
return importPD(importMap);
}
};
}
/**
* Test of matches method, of class CategoryVisibility.
*/
@Test
public void testMatches1() {
Visibility other = new UnrestrictedVisibility();
CategoryVisibility instance = new CategoryVisibility("A Cat");
boolean expResult = true;
boolean result = instance.matches(other);
assertEquals(expResult, result);
}