简体   繁体   中英

Kotlin infix function shadows/hides member function

I am just trying to write some examples with 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 .

The generated Main.java class has this method;

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;

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 .

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!

Replace

bind(UserService()).to(IUserService::class)

with

bind(UserService()).to(IUserService::class.java)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM