• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java 8 - Repeating Annotations

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?

author & internet detective
Posts: 40207
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cleaner code is a "real need"


I find the later easier to read, refactor, etc.
Posts: 26
  • 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:

{ @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.
These are the worst of times and these are the best of times. And this is the best tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic