mercredi 19 février 2020

Enforce method signature using annotations

I have written a custom annotation that I use to find methods that can be invoked via a IoT platform. It's a method level annotation:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DirectMethod {

    String value();

}

I look this annotation up in runtime, and to have the call succeed, the expected signature must be:

@DeviceMethod("metod")
public ReturnType methodName(final String data) {...}

i.e, the return type and the input parameters are crucial.

Is there any way to have an annotation be "smart" when its target type is METHOD? Like integrated IDE warnings and such. Or do I simply have to process each annotation manually at startup and have the startup procedure fail if any method breaks my intended method contract?





Aucun commentaire:

Enregistrer un commentaire