• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Q 4 H.Schildt (4): how far can annotations go?

 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear author,

Can annotations be used to enforce the use
of classes with a particular property?

For example, can I use a custom made annotation
to enforce the use of synchronized methods?

Cheers,

Gian Franco Casula
 
Author
Posts: 253
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gian:

Let me answer in very general terms. First, you can, indeed, create custom annotations. Thus, you could create an annotation that indicates that synchronized methods must be used. However, the enforcement of this annotation would be dependent upon a tool, such as the compiler, or a design tool. Since annotations can be obtained via reflection, its not hard to create a tool that could read your annotation.

Java 2, v5 includes several built-in annotations that are recognized by javac. For example, @override is a marker annotation that indicates that a method must be overridden.
[ August 25, 2004: Message edited by: Herb Schildt ]
 
I like you because you always keep good, crunchy cereal in your pantry. This tiny ad agrees:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic