【发布时间】:2020-04-23 16:32:20
【问题描述】:
我想知道如何从 Kotlin 中的 Java 类中引用重载方法。
例如在接口WebClient中有三个get方法:
HttpRequest<Buffer> get(int port, String host, String requestURI);
HttpRequest<Buffer> get(String host, String requestURI);
...
在 kotlin 中,我想引用具有三个参数的那个:
val methodReference : WebClient.(port : Int, host: String?, requestUrl: String?) -> HttpRequest<Buffer> = WebClient::get
但我收到以下错误:
None of the following functions can be called with the arguments supplied:
public abstract operator fun get(p0: Int, p1: String!, p2: String!): HttpRequest<Buffer!>! defined in io.vertx.ext.web.client.WebClient
public abstract operator fun get(p0: String!): HttpRequest<Buffer!>! defined in io.vertx.ext.web.client.WebClient
public abstract operator fun get(p0: String!, p1: String!): HttpRequest<Buffer!>! defined in io.vertx.ext.web.client.WebClient
有什么想法吗?
【问题讨论】:
-
您是否使用与您所指的函数相同的
Buffer类(和相同的HttpRequest)类? (不同包中的同名类很容易混淆,错误信息也不一定能区分。) -
@gidds 你是对的......程序员的盲目性。谢谢!