带有替代方法的重载方法值表 [英] Overloaded method value table with alternatives

查看:30
本文介绍了带有替代方法的重载方法值表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下编译器抱怨的代码:

I have following code the compiler complains:

val state: KTable[String, String]  = builder
  .table("BARY-PATH", Materialized.as("PATH-STORE"))

错误信息:

[error] /home/developer/Desktop/microservices/paths-stream/src/main/scala/io/khinkali/PathsTopology.scala:23:8: overloaded method value table with alternatives:
[error]   [K, V](x$1: String, x$2: org.apache.kafka.streams.kstream.Materialized[K,V,org.apache.kafka.streams.state.KeyValueStore[org.apache.kafka.common.utils.Bytes,Array[Byte]]])org.apache.kafka.streams.kstream.KTable[K,V] <and>
[error]   [K, V](x$1: String, x$2: org.apache.kafka.streams.Consumed[K,V])org.apache.kafka.streams.kstream.KTable[K,V]
[error]  cannot be applied to (String, org.apache.kafka.streams.kstream.Materialized[Nothing,Nothing,Nothing])
[error]       .table("BARY-PATH", Materialized.as("PATH-STORE"))
[error]        ^

然后我尝试了:

val state: KTable[String, String]  = builder
  .table[String, String]("BARY-PATH", Materialized[String, String,KeyValueStore[org.apache.kafka.common.utils.Bytes, Array[Byte]]].as("PATH-STORE"))

编译器仍然抱怨:

[error] /home/developer/Desktop/microservices/paths-stream/src/main/scala/io/khinkali/PathsTopology.scala:24:43: object org.apache.kafka.streams.kstream.Materialized is not a value
[error]       .table[String, String]("BARY-PATH", Materialized[String, String,KeyValueStore[org.apache.kafka.common.utils.Bytes, Array[Byte]]].as("PATH-STORE"))

我阅读了 API 文档 但想不通,我做错了什么?

I read the API docs but could not figure, what am I doing wrong?

方法实现:

 * Materialize a {@link StateStore} with the given name.
 *
 * @param storeName  the name of the underlying {@link KTable} state store; valid characters are ASCII
 * alphanumerics, '.', '_' and '-'.
 * @param <K>       key type of the store
 * @param <V>       value type of the store
 * @param <S>       type of the {@link StateStore}
 * @return a new {@link Materialized} instance with the given storeName
 */
public static <K, V, S extends StateStore> Materialized<K, V, S> as(final String storeName) {
    Topic.validate(storeName);
    return new Materialized<>(storeName);
} 

在Java中,我做到了

In Java, I did

KTable<String, String> soureTable = builder
    .table("BARY-PATH", Materialized.as("PATH-STORE"));

它就像一个魅力.

推荐答案

尝试在 as 方法之后移动泛型类型规范:

Try moving generic types specification after as method:

val state: KTable[String, String]  = builder
    .table[String, String]("BARY-PATH", Materialized.as[String, String,KeyValueStore[org.apache.kafka.common.utils.Bytes, Array[Byte]]]("PATH-STORE"))

正如您从 Java 签名中看到的,对于静态方法,您应该为方法而不是为类指定泛型类型.

as you may see from the Java signature, for static methods you should specify generic types for the method rather than for the class.

这篇关于带有替代方法的重载方法值表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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