简体   繁体   English

Kotlin中缀函数阴影/隐藏成员函数

[英]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.

相关问题 如何在REST函数的ResponseBuilder中调用Javascript函数? - How to call a Javascript function in the ResponseBuilder of REST function? Jackson JsonParseExceptionMapper和JsonMappingExceptionMapper阴影自定义映射器 - Jackson JsonParseExceptionMapper and JsonMappingExceptionMapper shadows custom mapper (Jquery)Ajax中的beforeSend函数有什么用 - what is the use beforeSend function in (Jquery) Ajax "为 lambda 函数构建 InvokeRequest 时没有这样的方法 memberName" - No such method memberName when building InvokeRequest for lambda function 如何使用打印功能实现react-pdf - How to implement react-pdf with print function 调用递归ajax时无法访问成功功能 - Cant access success function when call recursive ajax 向Jersey多部分表单数据功能添加注释会破坏它 - Adding annotations to a Jersey multipart-form-data function breaks it 响应状态200正常,但使用jquery错误功能 - Response statut 200 is OK but use jquery error function 良好实践:API 和 MVC - 我应该将方法/函数与 API 的 SQL 查询放在一起 - Good practice: API and MVC - where should I put method / function with SQL query for API 春季靴子ModelValidationException - Spring Boot Kotlin Jersey ModelValidationException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM