如何跳过Kotlin中泛型类型参数的规范?

如何跳过Kotlin中泛型类型参数的规范?,kotlin,Kotlin,这是我的主要职能 val client = ConnectionFactory.createClient() # <- Return lettice.io RedisClusterClient val conn = client.connect() val command = conn.sync() var index: String? = null index = readDataStructure(command, key) kotlin投诉错误:接口命令需要3个类型参数 我希

这是我的主要职能

val client = ConnectionFactory.createClient()  # <- Return lettice.io RedisClusterClient
val conn = client.connect()
val command = conn.sync()

var index: String? = null

index = readDataStructure(command, key)
kotlin投诉
错误:接口命令需要3个类型参数

我希望能够不指定K、V和T,因为我只是在编写一个一次性脚本


是否有Kotlin lang语法,允许我按原样传递
命令
变量?

我想您的目标是:

fun readDataStructure(command: RedisCommand<*,*,*>, key: String): String {
fun readDataStructure(命令:RedisCommand,键:String):String{
?

从Kotlin文档:

如果您不知道(或不关心)泛型类型可能是什么,可以使用星形投影:

fun printSize(items: List<*>) = println(items.size)
fun printSize(项目:列表)=println(项目.size)
使用具有星形投影一个或多个类型参数的泛型类型时,可以:

  • 使用根本不提及星形投影类型参数的任何成员
  • 使用返回星形投影类型参数的任何成员,但返回类型将显示为any?(除非类型参数受到约束,在这种情况下,您将获得约束中提到的类型)
  • 不使用任何将星形投影类型作为参数的成员

我想你是在追求:

fun readDataStructure(command: RedisCommand<*,*,*>, key: String): String {
fun readDataStructure(命令:RedisCommand,键:String):String{
?

从Kotlin文档:

如果您不知道(或不关心)泛型类型可能是什么,可以使用星形投影:

fun printSize(items: List<*>) = println(items.size)
fun printSize(项目:列表)=println(项目.size)
使用具有星形投影一个或多个类型参数的泛型类型时,可以:

  • 使用根本不提及星形投影类型参数的任何成员
  • 使用返回星形投影类型参数的任何成员,但返回类型将显示为any?(除非类型参数受到约束,在这种情况下,您将获得约束中提到的类型)
  • 不使用任何将星形投影类型作为参数的成员

您可以使用
RedisCommand
但是如果您在它上面调用任何需要知道类型的方法,那么您必须指定这些类型。我必须查看RedisCommand文档来进一步解释。您可以使用
RedisCommand
但是如果您在它上面调用任何需要知道类型的方法,那么您必须指定这些类型se类型。我必须查看RedisCommand文档以进一步解释。