I could not understand Java's annotation's default value.
This is my code:
import cn.hutool.core.util.ReflectUtil;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public class Question {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface Test {
String name = "123";
String name() default name;
}
@Test
private final String demo = null;
public static void main(String[] args) {
System.out.println(System.identityHashCode(Test.name));
System.out.println(System.identityHashCode(
ReflectUtil.getField(Question.class, "demo").getAnnotation(Test.class).name())
);
}
}
The result is:
1147985808
1789447862
Why is the same object's system hashCode different?