Comments (8)
Also tried 2.0.0-rc2 but the issue is still there.
from klock.
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.
@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.
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.
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.
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.
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.
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)
- Get locale of device HOT 1
- Format DateTimeTz HOT 7
- Deployment to Maven Central HOT 3
- add infix to functions? HOT 2
- Android java.lang.NoSuchMethodError HOT 3
- Jcenter is being sunsetted HOT 1
- How to handle daylight saving time? HOT 2
- Regex Breaks in Kotlin 1.5 HOT 2
- Strange casting of DateTime in runtime HOT 3
- Legacy JS support removed - intentional? HOT 5
- Doesn't have release version klock:klock-android HOT 1
- Where is the latest codes? HOT 3
- Update up to 1.6.0? HOT 4
- Adding support to iosSimulatorArm64 architecture HOT 4
- Missing watchosX64 artifacts in latest version 2.4.12 HOT 9
- Occasional bug in date formatter HOT 4
- Network error, ignore this
- Network error, ignore this
- Chinese Locale still use "am/pm" HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from klock.