About Question enthuware.ocpjp.ii.v11.2.3394 :
Moderator: admin
- 
				Sergiy Romankov
 - Posts: 31
 - Joined: Thu Feb 19, 2015 8:25 am
 - Contact:
 
Re: About Question enthuware.ocpjp.ii.v11.2.3394 :
@interface Meals{
Meal[] value();
String course() ;
}
@Repeatable(Meals.class)
@interface Meal{
int id() default 0;
String name();
}
			
			
									
									
						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 :
course() has no default value and there are no compilation error
			
			
									
									
						
		Online		
						
						
		
				
		
		
	- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.ii.v11.2.3394 :
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.
...
- 
				Sergiy Romankov
 - Posts: 31
 - Joined: Thu Feb 19, 2015 8:25 am
 - Contact:
 
Re: About Question enthuware.ocpjp.ii.v11.2.3394 :
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 :
@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
			
			
									
									
						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
		Online		
						
						
			
			
									
									
						
		
				
		
		
	- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.ii.v11.2.3394 :
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.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
		Online		
						
						
			
			
									
									
						
		
				
		
		
	- 
				admin
 - Site Admin
 - Posts: 10443
 - Joined: Fri Sep 10, 2010 9:26 pm
 - Contact:
 
Re: About Question enthuware.ocpjp.ii.v11.2.3394 :
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?Sergiy Romankov wrote: ↑Mon Feb 03, 2020 10:35 amWell 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 :
Thank you for answer
			
			
									
									
						Who is online
Users browsing this forum: No registered users and 38 guests