Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any substantive difference between declaring a class normally versus in a package object?

Tags:

scala

If I have a package com.example, I can create a class in that package like this:

package com.example {
  class MyClass
}

or like this:

package com {
  package object example {
    class MyClass
  }
}

In both cases, the resulting class is (as far as other Scala code is concerned, at least) com.example.MyClass.

There are certainly incidental differences. In the first instance, the resulting compiled class is com/example/MyClass.class whereas in the second it's com/example/package$MyClass.class but are there any substantive differences?

like image 209
Paul Butcher Avatar asked Jan 01 '12 23:01

Paul Butcher


1 Answers

The difference in generated class file names was discussed on scala-internals, and hopefully will disappear in Scala 2.10.

like image 156
retronym Avatar answered Sep 23 '22 18:09

retronym