i have a class in a lib whose constructor is marke...
# getting-started
b
i have a class in a lib whose constructor is marked as
internal
, but when i include that lib (via a maven dependency) in a java project, i can still access that constructor. am i misunderstanding the scope of
internal
?
m
Hmmm. Java doesn't 'understand' internal. For methods, I believe the Kotlin compiler creates the method with a mangled name, so you'd have to look at bytecode to see it. And Kotlin knows about internal, so will treat it properly. I guess it doesn't 'work' for constructors as you can't change its name.
b
hmm, darn. so this is no-package-private-in-kotlin strikes again i guess.
m
You could make the constructor private, and have an
invoke
function in the Companion that is internal. Code looks same in Kotlin, and Java won't find it. package-private has it's own issues, so I'm in agreement with Jetbrain's decision not to add it, but that's another conversation.
b
good idea, i'll try it with invoke and see how that goes
m
Let me know if it works. It's just a guess right now.
All depends on what the compiler actually does with the invoke behind the scenes, and I've never looked.
b
looks like that works
trying to call the companion invoke from java errors with "usage of kotlin internal declaration from different module"
m
Given that, I'd raise a bug on the internal constructor to let them know. And at least you have a reasonable workaround.
b
👍