1

I created a Scala object:

package myapp.data

import java.io.File
import myapp.models.NodeViewModel
import com.thoughtworks.xstream.XStream
import com.thoughtworks.xstream.io.xml.DomDriver

object ForumSerializer {
    def openFile(file : File) : NodeViewModel = {
        // doing something
    }

    def saveToFile(model : NodeViewModel) : Unit = {
        // doing something
    }
}

Then I tried to import it in another Java file

import myapp.ForumSerializer;

The error I get is:

Import myapp.ForumSerializer cannot be resolved.

What am I doing wrong?

marmistrz
  • 5,658
  • 10
  • 35
  • 92
  • 1
    Related: https://stackoverflow.com/questions/12284028/how-can-i-use-a-scala-singleton-object-in-java – 0__ Jun 04 '16 at 17:24

1 Answers1

2

Import it as ForumSerializer$. Scala adds a $, so the compiler doesn't get confused with the class, when you have both an object and a class of the same name. You can then access the singleton object using the generated MODULE$.

Luka Jacobowitz
  • 21,337
  • 5
  • 37
  • 57