Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7812147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:25:12+00:00 2026-06-02T04:25:12+00:00

I’m having trouble understanding why I can’t reference a scala enum type. The problem

  • 0

I’m having trouble understanding why I can’t reference a scala enum type.

The problem is that sometimes I can reference enums:

enum(UserStatus)

and sometimes it complains about not being able to find the enum

not found: type UserStatus

How come I sometimes cannot reference the Enumeration class?

The generated source for the enum seems to be ok, and it works great with another enum that I have which lives in the same place, same usage…

Any Suggestions?

More info

The generated source for the enum is:

public final class models.UserStatus extends java.lang.Object{
    public static final scala.Enumeration$Value Busy();
    public static final scala.Enumeration$Value Free();
    public static final scala.Enumeration$ValueSet$ ValueSet();
    public static final scala.Enumeration$Value withName(java.lang.String);
    public static final scala.Enumeration$Value apply(int);
    public static final int maxId();
    public static final scala.Enumeration$ValueSet values();
    public static final java.lang.String toString();
}

I’m trying to implement an enum mapper for play framework 2.0

def enumFormat[E <: Enumeration](enum: E): Formatter[E#Value] = new Formatter[E#Value] {
  def bind(key: String, data: Map[String, String]) = {
    Formats.stringFormat.bind(key, data).right.flatMap { s =>
      scala.util.control.Exception.allCatch[E#Value]
        .either(enum.withName(s))
        .left.map(e => Seq(FormError(key, "error.enum", Nil)))
    }
  }
  def unbind(key: String, value: E#Value) = Map(key -> value.toString)
}

And this method that calls the mapper

def enum[E <: Enumeration](enum: E): Mapping[E#Value] = of(enumFormat(enum))

This means that the mapper automatically converts between a enum when using the form binding

Pseudo code of usage.

package models {
  object UserStatus extends Enumeration {
    val Free = Value("free")
    val Busy = Value("busy")
  }

  case class User(
    status: UserStatus.Value = UserStatus.Free
  )
}

package controllers {
  imports models._
  val userForm = Form(
    mapping(
      "status" -> enum(UserStatus)
    )(User.apply)(User.unapply)
  )
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:25:14+00:00Added an answer on June 2, 2026 at 4:25 am

    Your problem may come from the fact that in Scala you can use the same identifier for a type and for a value.

    When you write the following:

    object Foo extends Enumeration {
      val A, B, C = Value
    }
    

    You define a Foo object, but you don’t define a Foo type. If you come from a Java background you may not find this behavior intuitive.

    So what’s the type of the Foo enumeration values? Their type is Foo.Value (that’s called a path dependent type).

    If you want to define a Foo type corresponding to the enumeration values type, you can alias the Foo.Value type:

    object Foo extends Enumeration {
      type Foo = Value    // Type alias
      val A, B, C = Value
    }
    

    Now you can refer to the enumeration type by writing Foo.Foo. You can import the fields of the Foo object to reduce the syntactic overhead:

    import Foo._
    def bar(foo: Foo): String = foo match {
      case A => "value A"
      case B => "value B"
      case C => "value C"
    }
    

    In the above code, the first line refers to the Foo object, and the second line refers to the Foo type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.