Page 1 of 1

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 9:26 am
by Sergiy Romankov
@interface Meals{
Meal[] value();
String course() ;
}

@Repeatable(Meals.class)
@interface Meal{

int id() default 0;
String name();
}

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 9:27 am
by Sergiy Romankov
course() has no default value and there are no compilation error

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 9:36 am
by admin
Please see section 9.6.3 of JLS 11:
...
An annotation type TC is a containing annotation type of T if all of the following are true:
1. TC declares a value() method whose return type is T[] .
2. Any methods declared by TC other than value() have a default value.
...

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 10:35 am
by Sergiy Romankov
Well the question is which definitions of repeatable annotation is correct ?

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 10:36 am
by Sergiy Romankov
@interface Meals{
Meal[] value();
String course() ;
}

@Repeatable(Meals.class)
@interface Meal{

int id() default 0;
String name();
}

@Meals(course = "", value = {@Meal(name="")})
public class Main {


}

And here is no problem

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 10:42 am
by admin
Sergiy Romankov wrote:
Mon Feb 03, 2020 10:36 am
@interface Meals{
Meal[] value();
String course() ;
}

@Repeatable(Meals.class)
@interface Meal{

int id() default 0;
String name();
}

@Meals(course = "", value = {@Meal(name="")})
public class Main {


}

And here is no problem
Well, JLS 9.6.3 is pretty clear that any methods declared by TC other than value() must have a default value in a containing annotation. So, if the above is working then I am not sure what we can do. I would go by the specification.

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 03, 2020 10:43 am
by admin
Sergiy Romankov wrote:
Mon Feb 03, 2020 10:35 am
Well the question is which definitions of repeatable annotation is correct ?
I see your point but in the given repeatable annotation there is a line @Repeatable(Meals.class). But if Meals is an invalid containing annotation, how can @Repeatable(Meals.class) be valid?

Re: About Question enthuware.ocpjp.ii.v11.2.3394 :

Posted: Mon Feb 17, 2020 7:34 am
by Sergiy Romankov
Thank you for answer