jeudi 8 novembre 2018

Reflection API + Annotations: how to send class-inheritor as parameter?

I have annotation & want to send class name there as parameter:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
@Documented
public @interface PostApiRequest {

    Class<?> value();
}

I attach annotation to method of parent class:

@PostApiRequest(value = ...)
@Override
public ResponseEntity<D> save(@RequestBody D dto) {

Application don't know, which inheritor shall call this method, than I want to send inheritor there to work with its properties later. I should see any like this:

@PostApiRequest(value = this.class)    //send inheritor
@Override
public ResponseEntity<D> save(@RequestBody D dto) {

but it not works.

Please, give advice, how to do it?





Aucun commentaire:

Enregistrer un commentaire