views:

322

answers:

3

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]))
A: 

Okay, i found out that you CAN use an array as an annotation parameter as seen here. So in principle, this should work:

@Remote(value = Array(classOf[MyEJBRemote]))
class MyEJB extends MyEJBRemote {

Here is my MyEJBRemote:

trait MyEJBRemote {
}

So the array is okay, but my next problem is a type mismatch coming from classOf[MyEJBRemote]. As it seems it's not possible to have a .class as an annotation parameter. This has also been discussed here, without any solution to this. Will do further investigation on this...

ifischer
+3  A: 

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.

retronym
A: 

As always a competent answer... thank you! This is a real show-stopper to use Scala in a JavaEE application. Changing the annotation is not an option for me. I wonder why it worked with Scala 2.7x. On this page the author implements the annotation like this:

@Remote {val value = Array(classOf[ITest])}
class TestBean extends ITest { ...

Which seems to work. Unfortunately, Scala 2.7x is also not an option for me...

ifischer