Class literals for annotation values


#1

There are several annotations that require class literals or even arrays of class literals, Remote or Resource come mind.

In Java I would write something like:

@Remote({FirstInterface.class, SecondInterface.class})
public class SampleEJB implements FirstInterface.class SecondInterface {

  @Resource(name = “datasources/first”, class = DataSource.class)
  private DataSource dataSource;

}

Is there a way to do this with Kotlin?


#2

Yes, named arguments will help, and to pass an array, you can use the array() function.


#3

Ok, I got the following working in the IDE

Singleton Remote(javaClass<TTenant>()) class TenantBean : TTenant { }

And the byte code in the IDE looks good

public final class com/acme/TenantBean implements jet/JetObject com/acme/TTenant  {

  // compiled from: Implementation.kt

  @Ljavax/ejb/Singleton;()

  @Ljavax/ejb/Remote;(value={com.acme.TTenant.class})

  @Ljet/runtime/typeinfo/JetClass;(signature=“Ljava/lang/Object;Lcom/acme/TTenant;”)


However I had to add kotlin-stdlib otherwise it would not compile on the command line and complain about

Unresolved reference: javaClass 

(I’m using Maven)