Is it possible to resolve ambiguity through annotations in Java

See English answers > method overloading for null argument 7

void bla(Integer a);
void bla(String a);

Basically, when I call bla (null), I get a vague call error Can you write or use some comments to solve this problem before the compilation phase?

Can I block the null option in bla (string a) before the compiler starts? I tried to write a notnull comment (but it started after the compilation phase)

See the following code:

@Documented
@Retention(RetentionPolicy.soURCE)
@Target({ElementType.METHOD,ElementType.FIELD,ElementType.PARAMETER,ElementType.LOCAL_VARIABLE})
public @interface NotNull1 {
    String value() default "";
}

void bla(@NotNull1 String a);

Solution

Converts null to the type of the method parameter

bla((Integer) null);
bla((String) null);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>