Details

      Description

      scala lib version: 2.8.0-SNAPSHOT (timestamp: 20091006.003811 buildNumber: 232)

      I can't pass the class of an object to a (Java) annotation (for ex, this one: https://svn.apache.org/repos/asf/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/annotations/Factory.java )

      The Factory annotation expects a Factory implementation, which is just class with a static method "newInstance", and so is done in Scala with an object.

      In Java, I write: @Factory( MyFactory.class )

      In scala, @Factory( classOf[MyFactory] ) won't work as MyFactory is an object and @Factory( MyFactory.getClass ) doesn't compile due to the error:

      "annotation argument needs to be a constant; found: MyFactory.getClass"

      I don't see any other way to pass the object's class as the annotation parameter.

        Issue Links

          Activity

          Hide
          Josh Suereth added a comment -

          The inability to grab an object's class outside of the constructor is killing us here.

          Show
          Josh Suereth added a comment - The inability to grab an object's class outside of the constructor is killing us here.
          Hide
          Jason Zaugg added a comment -

          I wonder, could classOf be rewritten these days as a macro? How about instanceClassOf / staticClassOf?

          Show
          Jason Zaugg added a comment - I wonder, could classOf be rewritten these days as a macro? How about instanceClassOf / staticClassOf ?
          Hide
          Jason Zaugg added a comment -

          https://groups.google.com/d/topic/scala-internals/D6LoxxxRbAA/discussion

          scala> object O
          defined module O
          
          scala> def impl[T: c.WeakTypeTag](c: Context): c.Expr[Class[_]] = {import c.universe._; c.Expr[Class[_]](Literal(Constant(weakTypeOf[T])))}
          impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[Class[_]]
          
          scala> def moduleClassOf[T <: Singleton]: Class[_] = macro impl[T]
          moduleClassOf: [T <: Singleton]=> Class[_]
          
          scala> moduleClassOf[O.type]
          res5: Class[O.type] = class O$
          
          Show
          Jason Zaugg added a comment - https://groups.google.com/d/topic/scala-internals/D6LoxxxRbAA/discussion scala> object O defined module O scala> def impl[T: c.WeakTypeTag](c: Context): c.Expr[Class[_]] = {import c.universe._; c.Expr[Class[_]](Literal(Constant(weakTypeOf[T])))} impl: [T](c: scala.reflect.macros.Context)(implicit evidence$1: c.WeakTypeTag[T])c.Expr[Class[_]] scala> def moduleClassOf[T <: Singleton]: Class[_] = macro impl[T] moduleClassOf: [T <: Singleton]=> Class[_] scala> moduleClassOf[O.type] res5: Class[O.type] = class O$
          Hide
          Adriaan Moors added a comment -

          Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw

          Show
          Adriaan Moors added a comment - Un-assigning to foster work stealing, as announced in https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/o8WG4plpNkw
          Hide
          Adriaan Moors added a comment -

          Unassigning and rescheduling to M6 as previous deadline was missed.

          Show
          Adriaan Moors added a comment - Unassigning and rescheduling to M6 as previous deadline was missed.

            People

            • Assignee:
              Unassigned
              Reporter:
              Francois Armand
              TracCC:
              Barry Kaplan, Ismael Juma, Johannes Rudolph
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:

                Development