Chapter 24

Annotations and Reflection

In general, metadata is data about your data. In the context of DBMSes, metadata can be information describing the way you store data, such as the table and field names or primary keys. Program code metadata is data about your code. Any Java class has its metadata embedded, and you can write a program that “asks” another class, “What methods do you have?” or similar questions about class fields, constructors and ancestors.

If you’ve ever looked at the source code of any Java class, you can easily identify Javadoc-style comments for classes, interfaces, variables, and methods. These comments may include specially formatted words.

In Eclipse you can select any Java class and press F3 to open the source code of this class. Because the previous lesson was about working with JTable, let’s open the source code of this class. In the top part of the code you’ll find a description similar to the one that follows (I removed a large portion of the text for brevity):

 /**  * The <code>JTable</code> is used to display and edit regular two-dimensional  * tables of cells.  * To enable sorting and filtering of rows, use a  * {@code RowSorter}.  *  * As for all <code>JComponent</code> classes, you can use  * {@link InputMap} and {@link ActionMap} to associate an  * {@link Action} object with a {@link KeyStroke} and execute the  * action under specified conditions.  * <p>  * <strong>Warning:</strong> Swing is not thread safe. For more  * information see <a ...

Get Java® Programming 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.