嗨,我目前面临 Java 泛型问题:我需要使用的方法具有此签名
static<K1,V1,K2,V2> void addMapper(JobConf job,
Class<? extends Mapper<K1,V1,K2,V2>> klass,
Class<? extends K1> inputKeyClass,
Class<? extends V1> inputValueClass,
Class<? extends K2> outputKeyClass,
Class<? extends V2> outputValueClass,
boolean byValue, JobConf mapperConf)
这就是我所说的
ChainMapper.addMapper(conf, NameMapper.class,
Object.class, Object.class, Object.class, Object.class,
false, nameYearConf);
其中 NameMapper 定义如下
public class NameMapper extends Mapper<Object, Object, Object, Object> { }
并且其他两个参数也正确初始化
JobConf conf = new JobConf(); JobConf nameYearConf = new JobConf(false);
当我尝试编译时,我收到以下错误
src\MeanYear.java:107: error: method addMapper in class ChainMapper cannot be applied to given types;
ChainMapper.addMapper(conf, NameMapper.class, Object.class,
^
required: JobConf,Class<? extends Mapper<K1,V1,K2,V2>>,Class<? extends K1>,Class<? extends V1>,Class<? extends K2>,Class<? extends V2>,boolean,JobConf
found: JobConf,Class<MeanYear.NameMapper>,Class<Object>,Class<Object>,Class<Object>,Class<Object>,boolean,JobConf
reason: no instance(s) of type variable(s) K1,V1,K2,V2 exist so that argument type Class<MeanYear.NameMapper> conforms to formal parameter type Class<? extends Mapper<K1,V1,K2,V2>>
where K1,V1,K2,V2 are type-variables:
K1 extends Object declared in method <K1,V1,K2,V2>addMapper(JobConf,Class<? extends Mapper<K1,V1,K2,V2>>,Class<? extends K1>,Class<? extends V1>,Class<? extends K2>,Class<? extends V2>,boolean,JobConf)
V1 extends Object declared in method <K1,V1,K2,V2>addMapper(JobConf,Class<? extends Mapper<K1,V1,K2,V2>>,Class<? extends K1>,Class<? extends V1>,Class<? extends K2>,Class<? extends V2>,boolean,JobConf)
K2 extends Object declared in method <K1,V1,K2,V2>addMapper(JobConf,Class<? extends Mapper<K1,V1,K2,V2>>,Class<? extends K1>,Class<? extends V1>,Class<? extends K2>,Class<? extends V2>,boolean,JobConf)
V2 extends Object declared in method <K1,V1,K2,V2>addMapper(JobConf,Class<? extends Mapper<K1,V1,K2,V2>>,Class<? extends K1>,Class<? extends V1>,Class<? extends K2>,Class<? extends V2>,boolean,JobConf)
我真的无法理解我做错了什么,我尝试了一些类似的示例并且编译并且它们有效。我也尝试了这里提供的一些示例,但没有成功。谢谢。