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 8433303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:21:01+00:00 2026-06-10T06:21:01+00:00

Please consider this code: object ResponseType extends Enumeration { val Listing, Album = Value

  • 0

Please consider this code:

object ResponseType extends Enumeration {
  val Listing, Album = Value
}

I can get the Symbol referring to this object like so:

import reflect.runtime.universe._
val s = typeOf[ResponseType.Value].asInstanceOf[TypeRef].pre.typeSymbol

Now, having this symbol, how can I get the actual ResponseType object?

  • 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-10T06:21:03+00:00Added an answer on June 10, 2026 at 6:21 am
    scala> val moduleClass = typeOf[ResponseType.Value].asInstanceOf[TypeRef].pre.typeSymbol
    moduleClass: reflect.runtime.universe.Symbol = object ResponseType
    
    scala> val module = moduleClass.owner.typeSignature.member(moduleClass.name.toTermName)
    module: reflect.runtime.universe.Symbol = object ResponseType
    
    scala> reflect.runtime.currentMirror.reflectModule(module.asModule).instance
    res9: Any = ResponseType
    

    Now, some explanation is in order, since this is quite an obscure implementation detail we’ve (yet!) been unable to abstract over in the public API.

    For every object Scala creates an underlying class that represents its signature, internally called module class. For example, if you compile object C the compiler will generate C$.class. That’s exactly the module class.

    Note that module classes are different from companion classes. Say, for case class C, the compiler will generate three symbols: type C, term C and (another one) type C, where the first type C represents the class C (which contains auto-generated copy, productPrefix, productArity etc) and the second type C represents a signature of object C (which contains auto-generated factory, extractor etc). There won’t be any name clashes, because the module class isn’t added to the symbol table directly and is only available through <module>.moduleClass.


    So what you actually get from your typeOf[ResponseType.Value].asInstanceOf[TypeRef].pre.typeSymbol incantation is a symbol that stands for a module class. There’s no function in the API that would get you to a module symbol from a module class. Internally in the compiler there surely is one, but we decided not to expose this implementation detail, because it might very well change soon.

    To get to a source module you need to go to owner, peek into the list of its members and look up an object there having the same name as the module class has. That’s exactly what moduleClass.owner.typeSignature.member(moduleClass.name.toTermName) does. One minor caveat is that if in the same scope you have a method with the same name, then member will return an overloaded symbol, and you’ll need to do something like .member(...).suchThat(_.isModule).

    After that it’s a piece of cake.


    Edit. Actually we’re thinking of introducing ClassSymbol.module that would return source module symbol for a module class and NoSymbol otherwise. Quite probably this will end up in RC1. Follow the release notes.

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

Sidebar

Related Questions

Please consider this code snippet: var ul = $(.list_b).find(li).remove().end(); $.each(Sites, function (index, value) {
please consider this code : 1-... 2-{ 3-... 4-SqlConnection cn=new SqlConnection(); 5-... 6-} if
please consider this code : 1)public static class MyClass 2){ 3) public static DateTime
Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
please consider this table: PK_Id Number Year Month Value ------------------------------------------------------------------------- 1 1 2000 5
Please consider this code: #include <iostream> template<typename T> void f(T x) { std::cout <<
I am trying to use R2WinBUGS using this example: code (Please only consider the
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
please consider this code: import xml.etree.ElementTree as ET import urllib XML_response = urllib.urlopen('http://www.navlost.eu/aero/metar/?icao=LWSK&dt0=2011-05-03+12%3A00%3A00&c=1&rt=metar').read() tree

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.