4 ms·
So how is Kotlin's interop with native code? I heard it was still pretty bad with Java despite some updates in that department. Swift can handle some API's but
by dep_b 9y ago
So how is Kotlin's interop with native code? I heard it was still pretty bad with Java despite some updates in that department. Swift can handle some API's but for real interop you can go back to Objective-C(++) wrappers with zero penalty.
- guelo 9y agoIt has very smooth interop, both languages can call each other's methods with no fuss. You can mix and match kotlin and Java files in the same directory. There are one-click tools for auto converting Java to kotlin. It is probably the main reason it beat out Scala on Android, along with the small runtime and superior IDE support.
- klodolph 9y agoI think the question was about e.g. Kotlin <-> C, not Kotlin <-> Java.
- agibsonccc 9y agoI see scala and tons of JNI. I see enough clojure as well. I am not experienced at all with kotlin. JVM languages in general tend to "ignore" making Java native interface "work". Usually you're stuck writing java there.
- nostrademons 9y agoYou mean Kotlin <-> Java or Kotlin <-> C? Kotlin Native (Kotlin <-> C & Objective C) just came out this month, is still a technology preview, and AFAIK is really rough around the edges. Haven't tried it. Kotlin has always had a very good Java interop story, in both directions. I've been using it for a year with Hadoop, AWS, JSoup, Rome, Jackson, DropWizard, Jetty, Apache Commons, ElasticSearch, Weka, and many other standard Java libraries and never had a problem. You basically drop in a library and go. Several of those libraries are either really old (eg. Weka was written in the last millenium) or pretty complex (Jackson is all annotation/reflection based), and I've never really had a problem. You do need to keep track of nulls yourself when crossing the Java boundary, and you need to understand what code Kotlin generates if you're implementing an interface or placing annotations, but both of those are well-documented and pretty typical tasks for any FFI work.
- swah 9y agoDid you choose to work with the JVM since leaving G?
- nostrademons 9y agoYeah, for this project at least. I've found that my choice of technology stack is largely dictated by a.) the libraries that are available and b.) the potential market I'm investigating. It's in Kotlin because I need Hadoop for at least part of the project, and one corpus I'm working with has a bunch of supporting tools in Java that aren't available on other platforms. I'd been doing a bunch with smartwatches a year or two back, so the project before this was in Swift (because when I talked to potential customers & looked at market share numbers, starting with anything other than the Apple Watch was indefensible), and two projects before then were in Java (because the Apple Watch wasn't out yet and Android Wear & Pebble were the only games in town). There were also a couple ideas that I'd tested out using just WordPress and YouTube, with no coding at all.
- izacus 9y agoInterop is dictated by the JVM itself - the whole point of JNI is that it translates data types into native types and properly manages access and lifecycle of objects that are otherwise owned by the JVM GC. Kotlin doesn't change any of that - you still need to go through JNI bridge and properly mark and pin objects as they're being owned by the other language.
- dep_b 9y agoSo it's as good/bad as in Java basically? And sorry for the poor phrasing in my question, I see how it can get confusing but I'm coming from iOS and I'm used to things being a bit more simple.