0

I am wondering if there is a way to do type cast while using an annotation in Java?

Here, maxRetries is a system property. ${maxRetries} returns a String object for me as IntelliJ tells me. Passing parameter maxRetries is int type. Is there a way to cast it to int type?

public interface InterfaceExample {
    @Retry(maxRetries = "${maxRetries}")
    method1();
}
package com.github.lianjiatech.retrofit.spring.boot.retry;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
public @interface Retry {
    int maxRetries() default 2;

    int intervalMs() default 100;

    RetryRule[] retryRules() default {RetryRule.RESPONSE_STATUS_NOT_2XX, RetryRule.OCCUR_IO_EXCEPTION};
}

heinels
  • 189
  • 1
  • 6

0 Answers0