0

I’ve got a java class A that has a static class as a member:

class A { ... static class B {...} } 

I see code in java that just do A.B to access class B. However, I cannot do the same thing in my kotlin class:

import org.mypackage.A class C { ... fun doSomething(o: Any) { if (o is A.B) { ...} ... } } 

(intellij marks B as red when I do A.B.
My use case: I have an object that I want to cast to B, like o is A.B.

I did mvn clean compile and got this error: Cannot access 'B': it is public/*package*/ in 'A'.

My question: how do I access B in my kotlin class?

1
  • 1
    Try making both A and B public and try again Commented Jul 25, 2018 at 22:39

1 Answer 1

1

If C has to import class A then it's not in the same package as A and B. If that's the case, how should C see class B which is not public but package level visible. It does not work in Java as well. (In Kotlin there is no package level visibility modifier, one would probably take "internal" but that's not the same. Those would see eachother)

Sign up to request clarification or add additional context in comments.

1 Comment

I found out that in Java the author used the same package path for his class as A.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.