[英]Kotlin infix function shadows/hides member function
I am just trying to write some examples with Kotlin. 我只是想和Kotlin一起写一些例子。 And what I did was to create a Jersey app, and everything was going well until I try to change the
Main.java
class to Main.kt
. 我所做的就是创建一个Jersey应用程序,一切进行得很好,直到我尝试将
Main.java
类更改为Main.kt
。
The generated Main.java
class has this method; 生成的
Main.java
类具有此方法。
public static HttpServer startServer() {
final ResourceConfig rc = new ResourceConfig()
.packages("com.kotlinexperiments")
.register(new AbstractBinder() {
@Override
protected void configure() {
bind(new UserService()).to(IUserService.class);
}
});
return GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);
}
And I try to convert it to a Kotlin file; 然后尝试将其转换为Kotlin文件;
fun startServer(): HttpServer {
val resourceConfig = ResourceConfig()
.packages("com.kotlinexperiments")
.register(object: AbstractBinder() {
override fun configure() {
bind(UserService()).to(IUserService::class)
}
})
return GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), resourceConfig)
}
The problem is, when you type in IDE with bind(someInstance).to(class)
it shows the member function, but when you run/debug it, it is going to infix function which is already defined in Tuples.kt
file, which is distributed with kotlin-stdlib
. 问题是,当您使用
bind(someInstance).to(class)
键入IDE时,它会显示成员函数,但是当您运行/调试它时,它将插入已经在Tuples.kt
文件中定义的Tuples.kt
。与kotlin-stdlib
一起kotlin-stdlib
。
The question is, is there a way to call the member function? 问题是,有没有一种方法可以调用成员函数? I try to escape the function name etc. but nothing worked actually.
我尝试转义函数名称等,但实际上没有任何作用。
Thnx! 日Thnx!
Replace 更换
bind(UserService()).to(IUserService::class)
with 同
bind(UserService()).to(IUserService::class.java)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.