I have the following kotlin code ```class Wrapper(...
# announcements
a
I have the following kotlin code
Copy code
class Wrapper(val value: ULong)
When I try instantiating it from Java I get
Copy code
Wrapper w = new Wrapper(5000L);
It says that the constructor is private. How do I instantiate such a class?
d
Make a constructor that accepts a normal
Long
for Java. Java does not support unsigned types or inline classes in general, as such you have to provide an alternative for Java.
a
Thanks, though seems like a bit of a work around. I thought the compiler would inline the
value
d
It does, but inline classes can have constructors (
init
could do validation). So if you could just pass the plain value from Java that code would be bypassed.
a
Thanks for the insight
oh constructor, can't JvmName that. yeah, you'll have to expose another one for Java interop of you need it.
d
And you should only do that for inline classes that do not have constructors /
init
blocks.
e
ULong doesn't, and you can take that into account when you write
d
Yes, just mentioning it as something to keep in mind.
👍 1