如何设置类的名字? [英] How to set names of classes?
问题描述
我的代码是:
public static< K,V> void initMapperJob(Job job,
Collection< WebPage.Field>字段,Class< K> outKeyClass,Class< V>
outValueClass,Class< ;? extends GoraMapper< String,WebPage,K,V>> mapperClass,
Class< ;? extends Partitioner< K,V>> partitionerClass,boolean reuseObjects)
throws ClassNotFoundException,IOException {
DataStore< String,WebPage> store = createWebStore(job.getConfiguration(),String.class,WebPage.class);
........
}
如下所示:
public static Collection Class< K> outKeyClass,Class< V> outValueClass,
Class< ;? extends GoraMapper< String,P,K,V> > mapperClass,
Class< ;? extends Partitioner< K,V>> partitionerClass,boolean reuseObjects)
throws ClassNotFoundException,IOException {
DataStore< String,P> store = createWebStore(job.getConfiguration(),
String.class,P.class);
....
}
我的问题是:如何通过java为下面的行设置类的泛型?
DataStore store = createWebStore(job.getConfiguration(),
String.class, P.class );
如果我设置为(P.class或P),则发生错误。
调用以下方法。
public static Class< K> keyClass,Class< V> persistentClass){...}
的参数并使用它(而不是P.class) 。那么您将需要到
public static< K,V,P extends PersistentBase,F extends Fields>
void initMapperJob(Job job,
Collection< F>字段,
Class< K> outKeyClass,Class< V> outValueClass,
Class< ;? extends GoraMapper< String,P, K,V>> mapperClass,
Class< ;? extends Partitioner< K,V>> partitionerClass,
boolean reuseObjects,
Class< P> pClass)throws ClassNotFoundException,IOException {
$ b DataStore< String,P> store = createWebStore(job.getConfiguration(),
String.class,pClass);
....
}
My code is:
public static <K, V> void initMapperJob( Job job,
Collection<WebPage.Field> fields, Class<K> outKeyClass, Class<V>
outValueClass, Class<? extends GoraMapper<String, WebPage, K, V>> mapperClass,
Class<? extends Partitioner<K, V>> partitionerClass, boolean reuseObjects)
throws ClassNotFoundException, IOException {
DataStore<String, WebPage> store = createWebStore(job.getConfiguration(), String.class, WebPage.class );
........
}
I change as like follows:
public static <K, V, P extends PersistentBase, F extends Fields> void initMapperJob(Job job,
Collection<F> fields,
Class<K> outKeyClass, Class<V> outValueClass,
Class<? extends GoraMapper<String, P, K, V>> mapperClass,
Class<? extends Partitioner<K, V>> partitionerClass, boolean reuseObjects)
throws ClassNotFoundException, IOException {
DataStore<String, P> store = createWebStore(job.getConfiguration(),
String.class, P.class );
....
}
My question is: how to set class of generics via java for the following line?
DataStore store = createWebStore(job.getConfiguration(), String.class, P.class );
If I set as like ( P.class or P) , an error has occurred .
The following method is called.
public static <K, V extends Persistent> DataStore<K, V> createWebStore(Configuration conf,
Class<K> keyClass, Class<V> persistentClass){...}
You need to add a parameter of type Class<P>
and use it (instead of P.class). you will then need to go to the site(s) where initMapperJob()
and add that extra parameter to the call.
public static <K, V, P extends PersistentBase, F extends Fields>
void initMapperJob(Job job,
Collection<F> fields,
Class<K> outKeyClass, Class<V> outValueClass,
Class<? extends GoraMapper<String, P, K, V>> mapperClass,
Class<? extends Partitioner<K, V>> partitionerClass,
boolean reuseObjects,
Class<P> pClass) throws ClassNotFoundException, IOException {
DataStore<String, P> store = createWebStore(job.getConfiguration(),
String.class, pClass);
....
}
这篇关于如何设置类的名字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!