Giter Site home page Giter Site logo

Comments (8)

weliem avatar weliem commented on May 27, 2024

Also tried 2.0.0-rc2 but the issue is still there.

from klock.

weliem avatar weliem commented on May 27, 2024

Did some more experimentation.....getMinutes() works and any other that returns a basic type like Int work. But the ones that returns some other com.soywiz.klock class don't work

from klock.

soywiz avatar soywiz commented on May 27, 2024

@weliem Klock is not intended to be consumed from Java. The main problem here is that we are using inline classes that is not yet available on Java until they implement value types with Valhalla.
Kotlin creates a special mangled names for functions using inlined types that probably won't be callable from Java. What Kotlin does is to mangle the function name + instead of receiving/returning for example TimeSpan, it receives/returns a Double, and the inline class functions are static.
This makes consuming the API from Java hard, or directly impossible. Once Java supports Valhalla, it is likely that Kotlin supports generating code using that stuff without having to mangling function names and stuff, and you will be able to consume it from modern Java versions directly, but for now, it is not possible.

from klock.

weliem avatar weliem commented on May 27, 2024

We choose Kotlin for it's interoperability with Java and other platforms. We have been using Klock successfully for the last year and calling Klock from Java has never been a problem. But now that we are upgrading from 1.8.3 to 2.0.0, our code is broken. So did something change in Klock? Did older versions not use inline classes?

Anyway, perhaps I can write some extentions to fix the interoperability issues....

from klock.

soywiz avatar soywiz commented on May 27, 2024

I was not aware that some people was using it with Java, and directly assumed it was not possible. Inline classes are experimental, so I think that's something unreliable at this point. You could check the exported class methods on both versions of the library, maybe the signature change because inline classes are experimental.
I'd suggest you to stick to 1.8.3 for now. On Kotlin new compiled versions are needed because Kotlin/Native doesn't have binary compatibility of the libraries, but with the JVM you should be safe to stick to older versions.

from klock.

weliem avatar weliem commented on May 27, 2024

I think our use case is very common: we have a library written in Kotlin Multi Platform which we use in our iOS, Android, and JVM applications. We use Klock in our library and it is also used in the external interface of the library. Hence interoperability with Java and Swift is essential...

Will try to find a workaround for now, but we would greatly appreciate it if future versions of your library would have improved interoperability.

from klock.

soywiz avatar soywiz commented on May 27, 2024

I'll investigate if we can do something regarding to binary compatibility, but if Kotlin started to use synthetic mangled methods with different signature on 1.4 because inline classes are experimental and there are no guarantees for them, I'm not sure if we could do anything. In any case, this library is opensource and public domain, if you have workarounds you want to include here, just make a PR with your proposals 👍

from klock.

weliem avatar weliem commented on May 27, 2024

The inline classes are ruining the fun ;-)

Anyway, I found a workaround using extensions. So for example:

fun DateTimeTz.getUtcMiliseconds(): Double {
    return utc.unixMillisDouble
}

From Java I can now call:

DateTimeTzExtensionsKt.getUtcMiliseconds(timestamp)

With that I can convert it to a Java Date object again...

from klock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.