[英]access (static class) member of parent java class in kotlin
I've got a java class A
that has a static class as a member: 我有一个具有静态类作为成员的Java类
A
:
class A {
...
static class B {...}
}
I see code in java that just do AB
to access class B. However, I cannot do the same thing in my kotlin class: 我在Java中看到仅执行
AB
来访问类B的代码。但是,在我的kotlin类中我不能做同样的事情:
import org.mypackage.A
class C {
...
fun doSomething(o: Any) {
if (o is A.B) { ...}
...
}
}
(intellij marks B
as red when I do AB
. (当我执行
AB
时,intellij将B
标记为红色。
My use case: I have an object that I want to cast to B
, like o is AB
. 我的用例:我有一个要投射到
B
的对象,例如o is AB
。
I did mvn clean compile
and got this error: Cannot access 'B': it is public/*package*/ in 'A'
. 我没有执行
mvn clean compile
并收到以下错误: Cannot access 'B': it is public/*package*/ in 'A'
。
My question: how do I access B
in my kotlin class? 我的问题:我如何在Kotlin课堂上访问
B
?
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. 如果C必须导入类A,则它与A和B不在同一个包中。如果是这样,C应该如何看待不是公共的但包级别可见的类B。 It does not work in Java as well.
它在Java中也不起作用。 (In Kotlin there is no package level visibility modifier, one would probably take "internal" but that's not the same. Those would see eachother)
(在Kotlin中,没有包装级别的可见性修改器,可能会带“内部”,但这并不相同。那些会互相看到)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.