1

I found an example of how to implement enum in Scala and here is what I have:

   package org.myproject

   object MyEnum extends Enumeration {
      type MyEnum = Value
      val val1, val2, val3 = Value
    }

But nonetheless, I have an error type MyEnum is not a member of package org.myproject:

package org.myproject.subnamespace

import org.myproject.MyEnum

abstract class MyClass {
  def myEnum123: MyEnum
}

Notice that they are located in the slightly different packages.

UPDATE: there are 2 errors, actually, it depends on how I define def:

package org.myproject.subnamespace

import org.myproject.MyEnum

abstract class MyClass {
  def myEnum123: MyEnum // not found: type MyEnum
  def myEnum123: org.myproject.MyEnum // type MyEnum is not a member of package org.myproject
}

What's wrong?

Alan Coromano
  • 24,958
  • 53
  • 135
  • 205

2 Answers2

1

Try this slight change in the import statement:

package org.myproject.subnamespace

import org.myproject.MyEnum._

abstract class MyClass {
  def myEnum123: MyEnum
}

You can check out the link below to better understand why you have to import the enumeration like that:

Understanding scala enumerations

Community
  • 1
  • 1
cmbaxter
  • 35,283
  • 4
  • 86
  • 95
0

An object declaration does not induce a type declaration, hence the error message. You probably want to declare

def myEnum123: MyEnum.MyEnum

See http://daily-scala.blogspot.ch/2009/08/enumerations.html for a small tutorial.

Malte Schwerhoff
  • 12,684
  • 4
  • 41
  • 71