This page is no longer maintained — Please continue to the home page at

Re: Scala object from Java

No replies
Seth Tisue
Joined: 2008-12-16,
User offline. Last seen 34 weeks 3 days ago.

>>>>> "Nils" == Nils Kilden-Pedersen writes:

Nils> How does one reference a Scala object (and companion object, if
Nils> it differs) from Java?

If you just have:

object S {
def foo = ...

You can refer to S itself from Java as S$.MODULE$ and if you want to
call foo you can just write

If the object is a companion object:

class S { ... }
object S {
def foo = ...

then the shorthand form won't be available and to call foo
you'll have to write S$.MODULE$.foo().

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland