Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java 8 - Repeating Annotations  RSS feed

 
Gauri Chiplunkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

Congratulations on your book and welcome on the forum!!
I have a couple of questions about repeatable annotations -
I was wondering where is a real need for the repeatable annotations, can't it be addressed by the parameters of annotation? Is it just cleaner code?
can we set a limit on the number of repetitions allowed?

Thanks,
Gauri
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37230
519
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cleaner code is a "real need"


vs


I find the later easier to read, refactor, etc.
 
Raoul Gabriel
Author
Greenhorn
Posts: 20
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gauri,

Thanks! You can't set a limit to the number of repetitions allowed.
But, yes in a nutshell repeatable annotations are just a syntactic sugar. Instead of using an explicit container inside the annotation:

@Authors(
{ @Author(name=”Raoul”), @Author(name=”Mario”) , @Author(name=”Alan”)}
)
class Book{}

you can more simply write:

@Author(name=”Raoul”) @Author(name=”Mario”) @Author(name=”Alan”)
class Book{ }

It will clean things up in enterprise applications where they often make use of this idiom.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!