如何设置类的名字? [英] How to set names of classes?

查看:112
本文介绍了如何设置类的名字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

  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){...} 


Class

的参数并使用它(而不是P.class) 。那么您将需要到 initMapperJob()所在的站点并将该额外参数添加到该调用中。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆