On my JRE, the following test passes:
public static @interface Bar {}
@Retention(RetentionPolicy.RUNTIME)
public @interface Foo
{
Bar value() default @Bar;
}
@Foo
public Object default1;
@Foo
public Object default2;
@Foo(@Bar)
public Object specified;
@Test
public void test() throws NoSuchFieldException, NoSuchMethodException
{
Foo d1 = getClass().getField("default1").getAnnotation(Foo.class);
Foo d2 = getClass().getField("default2").getAnnotation(Foo.class);
Foo s = getClass().getField("specified").getAnnotation(Foo.class);
Assert.assertSame(d1.value(), d2.value());
Assert.assertNotSame(d1.value(), s.value());
}
Is the behavior behind both of these assertions specified by Java? Is this a reliable condition to detect when a developer provided a value (albiet one that equals
the default)?