Annotation type-safety
The library introduces a concept of annotation type-safety. Consider the following example:
@Rpc
interface MyService
class MyServiceImpl : MyService
fun <T> withService() {}
The compiler can't guarantee that the passed type parameter is the one for which the code generation was run:
withService<MyService>() // ok
withService<MyServiceImpl>() // compile time ok, runtime throws
The compiler plugin enforces annotation type-safety by requiring type parameters to have specific annotations, like @Rpc
.
@Rpc
interface MyService
class MyServiceImpl : MyService
fun <@Rpc T : Any> withService() {}
withService<MyService>() // ok
withService<MyServiceImpl>() // compile time error
Annotation type-safety can be enforced recursively:
@Rpc
annotation class Grpc
@Grpc
interface MyGrpcService
fun <@Rpc T> acceptAnyRpcType()
fun <@Grpc T> acceptOnlyGrpcType()
acceptAnyRpcType<MyService>() // OK
acceptAnyRpcType<MyGrpcService>() // OK
acceptOnlyGrpcType<MyService>() // Compiler time error
acceptOnlyGrpcType<MyGrpcService>() // OK
Last modified: 25 June 2025