Using a Java RMI Class in Kotlin


#1

Hi,
I just started a Kotlin Gradle Project and the purpose is to create a Wrapper for my needs around a Java API.

The given API seems to be a RMI. The main entry class is a public interface which extends Remote.

The .jar is added to my dependencies and can be imported into my Kotlin files, but I can’t use the functions existing in the Java Library.

I’m using the latest Community Edition of Intellij IDEA.

Why am I not seeing the functions and how should I fix this ?

Something like this is the look of the Java API:

package com.bla.foo

public interface API extends Remote {
    boolean run() throws ApiExeption, RemoteExeption;
}

And similar to this is my Kotlin Code

import com.bla.foo
fun main(){
val k = API.run() <----- run isn’t shown
}


#2

You can’t call a member function on an interface. You need to get an instance of a class implementing the interface.

class SomeImplementation: API {
    fun run() : Boolean { TODO() }
}

fun main() {
    val impl = SomeImplementation()
    impl.run()
}

#3

Thank you!
Got it.


#4

If you’re new to programming (and based on your question it looks like it) you might want to go through a few tutorials. This is a good place to start. I personally would also suggest you take a look at a good book about programming, although I don’t know which books are good right now.
There is a list of kotlin books here