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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:31:40+00:00 2026-06-11T19:31:40+00:00

I am trying to use the new reflection API in Scala 2.10M7 to extract

  • 0

I am trying to use the new reflection API in Scala 2.10M7 to extract annotations on constructor arguments. The annotations are written in Java as I want them at run time and I got a warning recommending I use Java when I tried doing them in Scala.

I have successfully got a symbol for each constructor argument, and annotations… but I end up with things of type ClassFileAnnotArg (av in the code below). I am not sure what to do with these. Looking at the source code/scaladocs makes it appear that I want to split up on some case classes, but I could not work out how to do so.

I don’t think this question is specific to annotations on constructor args, but I wanted to use the more detailed scala reflection for them and can’t just use the Java annotation reflection mechanism.

import scala.reflect.runtime._
val ty = universe.typeOf[Test1]
val constructors = ty.member(universe.nme.CONSTRUCTOR)
for (constructor<-constructors.asTerm.alternatives.map{_.asMethod}) {
  println("Constructor = "+constructor)
  println("Overloaded = "+constructor.isOverloaded)
  for (pp<-constructor.params) {
    println("Constructor params")
    for (p<-pp) {
      println("  name="+p.name)
      println("  type="+p.typeSignature)
      for (a<-p.getAnnotations) {
        println("  annotation "+a.atp)
        for ((aname,av)<-a.assocs) {
          println("     "+aname.decoded+"="+av)
        }
      }
    }
  }
}

Is there any way to get an instance of the annotation object (as you do in Java annotations), or do you have to go through getAnnotations / check it is the one you want / iterate through the assocs / check it is the one you want / match the result to the expected type somehow / get the result?

  • 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-11T19:31:41+00:00Added an answer on June 11, 2026 at 7:31 pm

    Currently you can’t get an instance of the annotation object, though it’s a nice idea. I’ll try to squeeze it in before the RC1. upd. Oops, we’re in lockdown at the moment. This will have to wait until 2.10.1: https://issues.scala-lang.org/browse/SI-6423

    The conventional way is to pattern match on av against LiteralAnnotArg, ArrayAnnotArg and NestedAnnotArg (btw these names will be changed in RC1 to just LiteralArgument, ArrayArgument and `NestedArgument).

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

Sidebar

Related Questions

I'm trying to use the new OpenCV 2.0 API in MS Visual C++ 2008
I am trying to use the new immutable OptionParser in the Scala scopt 2.0.1
I'm trying to use the new ASP.NET Web API to do the following: A
I have a problem trying to solve a situation, when I use Java Reflection
I'm trying to use reflection to invoke a method whose name and arguments are
I am trying to use reflection instead of including a jar file. I want
I am trying to use new Google Cloud Messaging system but I have some
I am trying to use the new Eventmanager of the Zend Framework 2. I
I am trying to use nunits new way of exception handling but I am
I've been trying to use the new jquery-ui, and all but the resizable function

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.