Is there a significant difference between a class declaration in normal mode with respect to a package object?

If I have the com.example package, I can create a class in this package as follows:

 package com.example { class MyClass } 

or like this:

 package com { package object example { class MyClass } } 

In both cases, the resulting class (at least with respect to the other Scala code) is com.example.MyClass .

Of course, there are random differences. In the first case, the resulting compiled class is com/example/MyClass.class , while in the second it is com/example/package$MyClass.class , but are there any significant differences?

+7
source share
2 answers

The difference in the file names of the generated classes was discussed on scala -Internals and hopefully disappears in Scala 2.10.

+5
source

The only reason I can think of is because instead of inserting only class es, object or type into the package, you can put def s, val and var in the object.

0
source

All Articles