简体   繁体   中英

Accessing Class defined inside an Object in Scala

In Scala, I have two files each defining an Object. Both defined in the same package.

  • object1 has ClassA
  • object2 has the main method.

When I try to reference ClassA in object2, I get an error that ClassA cannot be found.

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()
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM