gpt4 book ai didi

java - 带有替代项的重载方法值表

转载 作者:行者123 更新时间:2023-11-29 08:31:45 24 4
gpt4 key购买 nike

我有以下编译器提示的代码:

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 docs但想不通,我做错了什么?

方法实现:

 * 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中,我做到了

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

它就像一个魅力。

最佳答案

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

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 签名中看到的那样,对于静态方法,您应该为方法而不是为类指定泛型类型。

关于java - 带有替代项的重载方法值表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47458725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com