• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

java 8 - Repeating Annotations

 
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
 
author & internet detective
Posts: 40207
816
Eclipse IDE VI Editor Java
  • 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.
 
Author
Posts: 26
12
  • 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.
 
These are the worst of times and these are the best of times. And this is the best tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic