IBM DB2 Manual page 167

Table of Contents

Advertisement

Annotations
Java annotations are a means for adding metadata to Java programs that can also
affect the way that those programs are treated by tools and libraries. Annotations
are declared with annotation type declarations, which are similar to interface
declarations. Java annotations can appear in the following types of classes or
interfaces:
v Class declaration
v Interface declaration
v Nested class declaration
v Nested interface declaration
You cannot include Java annotations directly in SQLJ programs, but you can
include annotations in Java source code, and then include that source code in your
SQLJ programs.
Example: Suppose that you declare the following marker annotation in a program
called MyAnnot.java:
public @interface MyAnot { }
You also declare the following marker annotation in a program called
MyAnnot2.java:
public @interface MyAnot2 { }
You can then use those annotations in an SQLJ program:
// Class annotations
@MyAnot2 public @MyAnot class TestAnnotation
{
// Field annotation
@MyAnot
private static final int field1 = 0;
// Constructor annotation
@MyAnot2 public @MyAnot TestAnnotation () { }
// Method annotation
@MyAnot
public static void main (String a[])
{
TestAnnotation TestAnnotation_o = new TestAnnotation();
TestAnnotation_o.runThis();
}
// Inner class annotation
public static @MyAnot class TestAnotherInnerClass { }
// Inner interface annotation
public static @MyAnot interface TestAnotInnerInterface { }
}
Enumerated types
An enumerated type is a data type that consists of a set of ordered values. The
SDK for Java version 5 introduces the enum type for enumerated types.
You cannot include Java enum types directly in SQLJ programs, but you can include
enums the following places:
v In Java source files (.java files) that you include in an SQLJ program
v In SQLJ class declarations
Example: The TestEnum.sqlj class declaration includes an enum type:
Chapter 4. SQLJ application programming
151

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents