What is a Java Annotation?

Discussion in 'Java' started by marcwentink@hotmail.com, May 30, 2006.

  1. Guest

    , May 30, 2006
    #1
    1. Advertising

  2. Robert Klemme, May 30, 2006
    #2
    1. Advertising

  3. wrote:
    > Probably a very stupid newbee question, but what is meant with
    > annotation


    A generic mechanism to add meta data to the source code. Tools, like the
    compiler, but also additional tools, can then do some magic tricks if
    they find an annotation in the code.

    Depending on the type of annotation, the meta data is removed when
    compiling, or is compiled into the class file. If you do the later, you
    can check the meta data during runtime, an do even more magic tricks
    while the program runs.


    /Thomas
    --
    The comp.lang.java.gui FAQ:
    ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
    http://www.uni-giessen.de/faq/archiv/computer-lang.java.gui.faq/
     
    Thomas Weidenfeller, May 30, 2006
    #3
  4. Chris Uppal Guest

    Thomas Weidenfeller wrote:

    > Depending on the type of annotation, the meta data is removed when
    > compiling, or is compiled into the class file.


    Nitpick: the metadata is always added to the classfile (or it wouldn't be a lot
    of use ;-) The distinction is between whether the /JVM/ discards the metadata
    as it loads the class, or retains it for runtime use by the application.

    -- chris
     
    Chris Uppal, May 30, 2006
    #4
  5. Dale King Guest

    Chris Uppal wrote:
    > Thomas Weidenfeller wrote:
    >
    >> Depending on the type of annotation, the meta data is removed when
    >> compiling, or is compiled into the class file.

    >
    > Nitpick: the metadata is always added to the classfile (or it wouldn't be a lot
    > of use ;-) The distinction is between whether the /JVM/ discards the metadata
    > as it loads the class, or retains it for runtime use by the application.


    Nit-nitpick:

    Annotations are not necessarily added to the class file. There are 3
    RetentionPolicy values defined that specify how long annotations are to
    be retained: SOURCE, CLASS, RUNTIME.

    The SOURCE value is used for things that are only significant to the
    compiler. For example, the Override and SuppressWarnings annotations are
    source only annotations.

    With the annotation processing API coming in JSE 6 (JSR 269) there will
    probably be many more uses for source only annotations.
    --
    Dale King
     
    Dale King, May 30, 2006
    #5
  6. Guest

    And I thank you for all the answers :)
    You're all very kinf
     
    , May 30, 2006
    #6
  7. Chris Uppal Guest

    Dale King" <"DaleWKing [at]gmail [dot] com wrote:

    > Annotations are not necessarily added to the class file. There are 3
    > RetentionPolicy values defined that specify how long annotations are to
    > be retained: SOURCE, CLASS, RUNTIME.


    I'd completely forgotten about SOURCE. Thanks for the correction.

    -- chris
     
    Chris Uppal, May 30, 2006
    #7
  8. "Chris Uppal" <-THIS.org> wrote in message
    news:447c4e3b$0$778$...
    > Dale King" <"DaleWKing [at]gmail [dot] com wrote:
    >
    >> Annotations are not necessarily added to the class file. There are 3
    >> RetentionPolicy values defined that specify how long annotations are to
    >> be retained: SOURCE, CLASS, RUNTIME.

    >
    > I'd completely forgotten about SOURCE. Thanks for the correction.


    Presumably if Java were being designed from scratch today Javadoc would be
    SOURCE.
     
    Mike Schilling, May 30, 2006
    #8
  9. Chris Uppal Guest

    Mike Schilling wrote:

    > Presumably if Java were being designed from scratch today Javadoc would be
    > SOURCE.


    Quite possibly. An even more interesting possibility (IMO) would be to give it
    CLASS status.

    Classfile format is a high-level programming language anyway, so why not ship
    the API documentation along with the "code" ?

    -- chris
     
    Chris Uppal, May 31, 2006
    #9
  10. "Chris Uppal" <-THIS.org> wrote in message
    news:447d6b7d$0$664$...
    > Mike Schilling wrote:
    >
    >> Presumably if Java were being designed from scratch today Javadoc would
    >> be
    >> SOURCE.

    >
    > Quite possibly. An even more interesting possibility (IMO) would be to
    > give it
    > CLASS status.
    >
    > Classfile format is a high-level programming language anyway, so why not
    > ship
    > the API documentation along with the "code" ?


    In some cases, security via obfuscation.
     
    Mike Schilling, May 31, 2006
    #10
  11. Chris Uppal Guest

    Mike Schilling wrote:

    [me:]
    > > Classfile format is a high-level programming language anyway, so why not
    > > ship
    > > the API documentation along with the "code" ?

    >
    > In some cases, security via obfuscation.


    Well, there's nothing to say that the info couldn't be stripped out, or never
    added in the first place (cf. debugging info).

    But it was just an idle thought ;-)

    -- chris
     
    Chris Uppal, May 31, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond McCrae
    Replies:
    2
    Views:
    1,499
    Raymond McCrae
    Mar 3, 2004
  2. srini

    java.text.Annotation

    srini, Apr 24, 2004, in forum: Java
    Replies:
    0
    Views:
    517
    srini
    Apr 24, 2004
  3. Marioli
    Replies:
    3
    Views:
    2,469
    Marioli
    Dec 28, 2006
  4. pek
    Replies:
    2
    Views:
    1,077
  5. Alberto Sfolcini

    Spring injection with java annotation?

    Alberto Sfolcini, Apr 24, 2008, in forum: Java
    Replies:
    6
    Views:
    2,253
    Alberto Sfolcini
    Apr 30, 2008
Loading...

Share This Page