2

I'm aware that it's possible to link Java programs with Matlab. Is it therefore possible to link any JVM languages with Matlab? I would suspect that's the case -- presumably Matlab can't tell and doesn't care how the .class files got created -- but I am hoping someone has some specific information about it. I couldn't find anything about it on the Matlab web site.

I'm interested in the moment in Kotlin (I can explain if anyone is interested) but I would be interested to know if it's possible for any JVM language.

1 Answers1

0

Looks like it is possible, here's a proof of concept. I'm working on macOS with Kotlin and JDK installed via Homebrew.

$ cat happyBirthday.kt 
class MyHappyBirthday {
    constructor () {}
    fun happyBirthday(name: String, age: Int): String {
        return "Happy ${age}th birthday, $name!"
    }
}

$ kotlinc -d /tmp happyBirthday.kt

and then in Matlab:

>> javaaddpath('/tmp')
>> javaaddpath('/usr/local/Cellar/kotlin//1.3.61/libexec/lib/kotlin-stdlib.jar')
>> foo=MyHappyBirthday()                                                        

foo =

MyHappyBirthday@5fd9b663

>> foo.happyBirthday('Foo',23992)                                               

ans =

Happy 23992th birthday, Foo!

Obviously one would have to include any other Kotlin jars in Matlab's Java classpath. Also obviously this is just a tiny example and there's plenty of room to run into complications, but on the face of it this is promising enough to keep going. Finally, I didn't try any other JVM languages but I would guess it run along similar lines.