0

I am defining a scala enum object

object LogType extends Enumeration{
    val value1,value2=Value
}

But getting an error :

object Enumeration is not a member of package scala Note: class Enumeration exists, but it has no companion object.

What might be the reason?

Bilesh Ganguly
  • 3,792
  • 3
  • 36
  • 58
Sandeep Das
  • 1,010
  • 9
  • 22
  • I'm able to successfully compile a `.scala` file containing just the snippet you posted. Please post code that reproduces the error. – Ben Mar 17 '16 at 10:39
  • I tried with scala shell ..its working fine .But in eclipse it is giving error – Sandeep Das Mar 17 '16 at 13:51
  • In that case it sounds like an IDE issue, not a language issue. Do you get an error when you compile your project? – Ben Mar 17 '16 at 13:57

1 Answers1

3

Try example from scaladocs. It looks like you have to define type.

object Main extends App 
{
   object WeekDay extends Enumeration 
   {
       type WeekDay = Value
       val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value
   } 

   import WeekDay._
   def isWorkingDay(d: WeekDay) = ! (d == Sat || d == Sun)
   WeekDay.values filter isWorkingDay foreach println
}
Flow
  • 23,572
  • 15
  • 99
  • 156
Pavel
  • 1,519
  • 21
  • 29
  • The type alias isn't required - see [this answer](http://stackoverflow.com/a/11067507/4070984) – Ben Mar 17 '16 at 10:41