Is it possible to use annotation classes from Java if they have generics?
Kotlin (as opposed to Java) supports generics for annotation classes (Java’s @interface
).
interface Contract
class ContractImpl: Contract
annotation class Annotated<C: Contract>(val contract: KClass<C>)
@Annotated<ContractImpl>(ContractImpl::class)
fun function() {}
However, when I try to use this annotation from Java, I get an error “Incompatible types. Found: 'java.lang.Class, required: ‘java.lang.Class’”
@Annotated(contract = ContractImpl.class)
void function() {}
Since I cannot do @Annotated<ContractImpl>
in Java, is there any way to use this annotation?