This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Annotation and object.getClass

1 reply
fanf
Joined: 2009-03-17,
User offline. Last seen 2 years 30 weeks ago.

Hello !

I need to pass a class type to a Java annotation that expects a static
method implementation (a factory)

In Java, I have something like:

8<-------- Java ----------
@Factory( TestFactory.class )
8<------------------------

In scala, as I want to implement the expected static method, TestFactory
is an object.

But in scala (2.8-SNAPSHOT, given by maven this morning)

8<---------- Scala -----------
@Factory( classOf[TestFactory] )
8<----------------------------

obviously won't work ( classOf only works with class, not object), and:

8<---------- Scala -----------
@Factory( TestFactory.getClass )
8<------------------------

fails with: "error: annotation argument needs to be a constant; found:
TestFactory.getClass"

What should I do to pass an object class to an annotation ?

fanf
Joined: 2009-03-17,
User offline. Last seen 2 years 30 weeks ago.
Re: Annotation and object.getClass

On Wed, Oct 7, 2009 at 12:52 PM, Francois wrote:
> 8<---------- Scala -----------
> @Factory( TestFactory.getClass )
> 8<------------------------
> fails with: "error: annotation argument needs to be a constant; found:
> TestFactory.getClass"

IRC seems to think that there is no other way to pass an object class
to an annotation, so I opened a ticket:
https://lampsvn.epfl.ch/trac/scala/ticket/2453

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland