Just found that `internal` kotlin classes are `pub...
# announcements
m
Just found that
internal
kotlin classes are
public
to java code. How to write kotlin library without exposing all classes to java?
1
c
Doesn't kotlin do name mangling to avoid allowing Java to see those internal types and functions? We had to explicitly annotate it not to do that for dagger modules where we needed the annotation processor to consume them correctly.
m
Well, java code sees the internal classes, I just tested accessing internal object - IDE complains about it but compiler has no issue with it.
a
Until we have better Java interop, I don't think its currently possible to fully hide a class from Java consumer. I wish we can at least annotate something like
@JvmPackageVisibility
for package private class since that visibility is super helpful for library devs to cater for Java consumer. In any case, you can look into
@JvmSynthetic
. It only applies to functions, fields etc though, and not applicable to classes. You can, however, use that with
internal
, which while the classes are still visible, the methods will at least be hidden from Kotlin and Java consumer.