0

我的代码是:

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

我改变如下:

        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 );

....
      }

我的问题是:如何通过 java 为以下行设置泛型类?

DataStore store = createWebStore(job.getConfiguration(), String.class, P.class );

如果我设置为like(P.class或P),则发生错误。

调用以下方法。

public static <K, V extends Persistent> DataStore<K, V> createWebStore(Configuration conf,
      Class<K> keyClass, Class<V> persistentClass){...}
4

1 回答 1

1

您需要添加类型参数Class<P>并使用它(而不是 P.class)。然后,您将需要转到该站点initMapperJob()并将该额外参数添加到调用中。

    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);

    ....
  }
于 2013-07-23T16:04:07.603 回答