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

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post by Sergiy Romankov »

@interface Meals{
Meal[] value();
String course() ;
}

@Repeatable(Meals.class)
@interface Meal{

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

Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post by Sergiy Romankov »

course() has no default value and there are no compilation error

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
...
If you like our products and services, please help us by posting your review here.

Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post by Sergiy Romankov »

Well the question is which definitions of repeatable annotation is correct ?

Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.
If you like our products and services, please help us by posting your review here.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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?
If you like our products and services, please help us by posting your review here.

Sergiy Romankov
Posts: 31
Joined: Thu Feb 19, 2015 8:25 am
Contact:

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

Post by Sergiy Romankov »

Thank you for answer

Post Reply

Who is online

Users browsing this forum: No registered users and 89 guests