Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala 2.8: use Java annotation with an array parameter

I'm trying to implement an JavaEE Session Bean with Scala 2.8.
Because it's a Remote Session Bean, i have to annotate it with the following Java Annotation:

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Remote {
  Class[] value() default {};
} 

I only found this example for scala 2.7. In Scala 2.7, its possible to define the session bean like this:

@Remote {val value = Array(classOf[MyEJBRemote])}
class MyEJB
...

How can i use this annotation the same way with Scala 2.8? I already tried many different versions, all resulting in "annotation argument needs to be a constant", "illegal start of simple expression". All of these definitions don't work:

@Remote{val value = Array(classOf[MyEJBRemote])}
@Remote(val value = Array(classOf[MyEJBRemote]))
@Remote(Array(classOf[MyEJBRemote]))
like image 602
Wolkenarchitekt Avatar asked May 16 '10 00:05

Wolkenarchitekt


1 Answers

You've got the syntax right in your answer. The problem is that the @Remote annotation uses the raw type Class rather than Class<?>. Java raw types are an unfortunate consequence of the backwards compatibility constraints from Java 1.4 to Java 1.5, and common source of bugs in the Scala compiler.

I found bug #3429 describing basically the same problem, and added your particular problem as another test case.

The only workaround would be to take the source code from the problematic annotation, replace Class with Class<?>, recompile them, and put that JAR in front of the classpath to Scalac. Other than that, you should vote for the bug adding your email to the CC list.

like image 145
retronym Avatar answered Oct 21 '22 07:10

retronym