[英]Accessing Class defined inside an Object in Scala
In Scala, I have two files each defining an Object. 在Scala中,我有两个文件,每个文件定义一个对象。 Both defined in the same package. 两者都在同一包中定义。
When I try to reference ClassA in object2, I get an error that ClassA cannot be found. 当我尝试在object2中引用ClassA时,出现一个错误,提示找不到ClassA。
What am I doing wrong? 我究竟做错了什么? If the objects are in the same default namespace, shouldn't they be able to see each other? 如果对象位于相同的默认名称空间中,它们是否不应该能够看到对方?
Have you tried this: 您是否尝试过:
object object2{
def main(args: Array[String]) {
val a = new object1.ClassA()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.