我在运行maven编译此类时遇到了错误,但在执行时似乎可以正常工作。我查看了很多与此主题相关的帖子,但无法使其正常工作。
编辑 - 删除原始代码段并替换
编辑 - 提供MCVE-非常简化的版本
顺便说一句,这是在Java 6上运行的。
[错误] 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile),项目 Test:编译失败:编译失败: [错误]...\src\main\java\common\main\MainTester.java:[14,18] 类型参数 common.mapping.rule.MappingRule 不在其范围内 [ERROR]...\src\main\java\common\handler\MappingProtocolHandler.java:[10,60] 类型参数 common.mapping.rule.MappingRule 不在其范围内
public class MainTester {
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
ProtocolHandler<MappingRule> mappingProtocolHandler = new MappingProtocolHandler();
Map<String, List<MappingRule>> protocols = mappingProtocolHandler.getProtocols();
System.out.println(protocols);
}
}
ProtocolHandler和Child类:
public abstract class ProtocolHandler<E extends Rule<?, ?>> {
public Map<String, List<E>> getProtocols() {
return getProtocolsForRequest();
}
protected abstract Map<String, List<E>> getProtocolsForRequest();
}
@SuppressWarnings("rawtypes")
public class MappingProtocolHandler extends ProtocolHandler<MappingRule>{
@Override
protected Map<String, List<MappingRule>> getProtocolsForRequest() {
return new HashMap<String, List<MappingRule>>();
}
}
规则类:
public interface Rule<F, T> {
public void execute(F object, T object2);
}
public abstract class BaseRule<F, T> implements Rule<F, T>, Comparable<BaseRule<F, T>> {
}
public abstract class MappingRule<F,T> extends BaseRule<F, T> implements CustomAttributes{
}
public abstract class InputRule extends MappingRule<Object, Map<String,Object>> {
}
public abstract class OutputRule extends MappingRule<Map<String, Object>, Object> {
}
public interface CustomAttributes {
}
处理程序类:
public abstract class ProtocolHandler<E extends Rule<?, ?>> {
public Map<String, List<E>> getProtocols() {
return getProtocolsForRequest();
}
protected abstract Map<String, List<E>> getProtocolsForRequest();
}
@SuppressWarnings("rawtypes")
public class MappingProtocolHandler extends ProtocolHandler<MappingRule>{
@Override
protected Map<String, List<MappingRule>> getProtocolsForRequest() {
return new HashMap<String, List<MappingRule>>();
}
}
[错误] 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile),项目 Test:编译失败:编译失败: [错误]...\src\main\java\common\main\MainTester.java:[14,18] 类型参数 common.mapping.rule.MappingRule 不在其范围内 [ERROR]...\src\main\java\common\handler\MappingProtocolHandler.java:[10,60] 类型参数 common.mapping.rule.MappingRule 不在其范围内
mappingProtocolHandler
字段的类。 - Sotirios Delimanolis