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

  • Home
  • SEARCH
  • 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 8401743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:53:01+00:00 2026-06-09T21:53:01+00:00

I would like to programmatically determine all properties of a Scala class at runtime.

  • 0

I would like to programmatically determine all properties of a Scala class at runtime. For instance, for the following Scala class I would like to determine that the methods name1, name3, name4, and name5 are getters for properties of A:

class A(val name1: String, private val name2: String) {
  val name3 = ""
  var name4 = ""
  def name5 = ""
  def name6() = ""
}

Most of the work can be done with Java’s reflection API. Unfortunately I was not able to detect the difference between name5 and name6(). Therefore I started a next trial using the ScalaSigParser, but ScalaSig’s flags for name5 and name6() are unfortunately also the same. Here is my code:

def gettersOf(clazz: Class[_]) = {
  for (ssig <- ScalaSigParser.parse(clazz))
  yield {
    ssig.symbols.toList.collect{
      case m: MethodSymbol => m
    }.filter(m => (m.symbolInfo.flags & 0xFFFFF) == 0x200)
  }
}

gettersOf(classOf[A]).get.foreach{m =>
  println(m.name + ": " + m)
}

As you can see in the following output both methods differ only in the info value:

name1: MethodSymbol(name1, owner=0, flags=28400200, info=22 ,None)
<init>: MethodSymbol(<init>, owner=0, flags=200, info=38 ,None)
name3: MethodSymbol(name3, owner=0, flags=8400200, info=45 ,None)
name4: MethodSymbol(name4, owner=0, flags=8000200, info=45 ,None)
name4_$eq: MethodSymbol(name4_$eq, owner=0, flags=8000200, info=54 ,None)
name5: MethodSymbol(name5, owner=0, flags=200, info=45 ,None)
name6: MethodSymbol(name6, owner=0, flags=200, info=66 ,None)

However, info does not seem to return static constants. If you add another method to the class the info value of name6 will change while there seems to be some stability:

  • name3, name4, and name5 have always the same info value
  • name6 and name5 have always different info values

Does someone know the meaning of info and how one can use it to surely determine which kind of method it is?

Related questions:

  • How does Scala know the difference between “def foo” and “def foo()”?
  • 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-09T21:53:02+00:00Added an answer on June 9, 2026 at 9:53 pm

    Your best bet is to use a reflection API of the coming Scala 2.10.

    Here’s how to get the properties of a type in 2.10.0-M6:

    scala> import reflect.runtime.universe._
    import reflect.runtime.universe._
    
    scala> typeOf[A].members.view.filter{_.isValue}.filter{!_.isMethod}.toList
    res0: List[reflect.runtime.universe.Symbol] = List(variable name4, value name3, value name2, value name1)
    

    Unfortunately there’s not much reading material on it yet. There are some answered questions on SO though. For instance, this question might be of interest to you. Also please check out this blogpost by Daniel Sobral.

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

Sidebar

Related Questions

i would like to programmatically access via python all the mail that exists on
I would like to programmatically determine language that content of a website is written
I would like to programmatically perform a check on the APK's signature at runtime.
I would like to run programmatically an instance of TestNG test. My test is
I am writing a web development targets file and would like to programmatically determine
Using .NET, I would like to programmatically get a list of all the groups
I would like to determine the operating system of the host that my Java
I would like to programmatically check the value of, and be able to toggle
I would like to programmatically set maxLength property of TextView as I don't want
I would like to create programmatically an animation for the background color of 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.