I have two versions of attributes ATTR8 one with default value and other one with out default value. My Driver code will compiles with one version and executes with the other version with out throwing 'AnnotationTypeMismatchError'
The following is the description of the the above context.
<console>
vishalb:/home/vv145429/tiger/src/metadata/test53 374 % ls
./ ../ ATTR8.java* ATTR9.java Test4.java* script.ksh test53.cfg
vishalb:/home/vv145429/tiger/src/metadata/test53 375 % javac -source 1.5 ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 376 % javac -source 1.5 Test4.java
Note: Test4.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
vishalb:/home/vv145429/tiger/src/metadata/test53 377 % \rm ATTR8.class
vishalb:/home/vv145429/tiger/src/metadata/test53 378 % mv ATTR8.java ATTR8.java.bak
vishalb:/home/vv145429/tiger/src/metadata/test53 379 % mv ATTR9.java ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 380 % javac -source 1.5 ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 381 % java Test4
vishalb:/home/vv145429/tiger/src/metadata/test53 382 % ls
./ ATTR8.class ATTR8.java.bak* Test4.java* test53.cfg
../ ATTR8.java Test4.class script.ksh
vishalb:/home/vv145429/tiger/src/metadata/test53 389 % cat ATTR8.java
import java.lang.annotation.*;
/**
* Default value for the java_version attribute what droped.
*
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ATTR8 {
String ClassName();
String Date();
String Author();
String Place();
String version();
String java_version() default "1.4";
}
vishalb:/home/vv145429/tiger/src/metadata/test53 390 % cat ATTR9.java
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface ATTR8 {
String ClassName();
String Date();
String Author();
String Place();
String version();
String java_version();
}
vishalb:/home/vv145429/tiger/src/metadata/test53 391 % cat Test4.java
@ATTR8(ClassName="Test4",
Date="5th Aug 2003",
Author="Tester",
Place="Bangalore",
version="1.5"
)
public class Test4 {
public static void main(String arg[]) {
boolean fail = false;
try {
Class cls = Class.forName("Test4");
Class atr_cls = Class.forName("ATTR8");
if (cls.isAnnotationPresent(atr_cls)) {
ATTR8 atr1 = (ATTR8) cls.getAnnotation(atr_cls);
if ( ! atr1.ClassName().equals("Test4")) {
System.out.println(" Class Name "+atr1.ClassName());
fail = true;
}
if ( ! atr1.Date().equals("5th Aug 2003")) {
System.out.println(" Date "+atr1.Date());
fail = true;
}
if ( ! atr1.Author().equals("Tester")) {
System.out.println(" Date "+atr1.Author());
fail = true;
}
if ( ! atr1.Place().equals("Bangalore")) {
System.out.println(" Date "+atr1.Place());
fail = true;
}
if ( ! atr1.version().equals("1.5")) {
System.out.println(" version "+atr1.version());
fail = true;
}
} else {
fail = true;
}
}catch(Exception exp) {
exp.printStackTrace();
fail = true;
}
if (fail) {
System.exit(1);
} else {
System.exit(0);
}
}
}
</console>
The following is the description of the the above context.
<console>
vishalb:/home/vv145429/tiger/src/metadata/test53 374 % ls
./ ../ ATTR8.java* ATTR9.java Test4.java* script.ksh test53.cfg
vishalb:/home/vv145429/tiger/src/metadata/test53 375 % javac -source 1.5 ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 376 % javac -source 1.5 Test4.java
Note: Test4.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
vishalb:/home/vv145429/tiger/src/metadata/test53 377 % \rm ATTR8.class
vishalb:/home/vv145429/tiger/src/metadata/test53 378 % mv ATTR8.java ATTR8.java.bak
vishalb:/home/vv145429/tiger/src/metadata/test53 379 % mv ATTR9.java ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 380 % javac -source 1.5 ATTR8.java
vishalb:/home/vv145429/tiger/src/metadata/test53 381 % java Test4
vishalb:/home/vv145429/tiger/src/metadata/test53 382 % ls
./ ATTR8.class ATTR8.java.bak* Test4.java* test53.cfg
../ ATTR8.java Test4.class script.ksh
vishalb:/home/vv145429/tiger/src/metadata/test53 389 % cat ATTR8.java
import java.lang.annotation.*;
/**
* Default value for the java_version attribute what droped.
*
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface ATTR8 {
String ClassName();
String Date();
String Author();
String Place();
String version();
String java_version() default "1.4";
}
vishalb:/home/vv145429/tiger/src/metadata/test53 390 % cat ATTR9.java
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
public @interface ATTR8 {
String ClassName();
String Date();
String Author();
String Place();
String version();
String java_version();
}
vishalb:/home/vv145429/tiger/src/metadata/test53 391 % cat Test4.java
@ATTR8(ClassName="Test4",
Date="5th Aug 2003",
Author="Tester",
Place="Bangalore",
version="1.5"
)
public class Test4 {
public static void main(String arg[]) {
boolean fail = false;
try {
Class cls = Class.forName("Test4");
Class atr_cls = Class.forName("ATTR8");
if (cls.isAnnotationPresent(atr_cls)) {
ATTR8 atr1 = (ATTR8) cls.getAnnotation(atr_cls);
if ( ! atr1.ClassName().equals("Test4")) {
System.out.println(" Class Name "+atr1.ClassName());
fail = true;
}
if ( ! atr1.Date().equals("5th Aug 2003")) {
System.out.println(" Date "+atr1.Date());
fail = true;
}
if ( ! atr1.Author().equals("Tester")) {
System.out.println(" Date "+atr1.Author());
fail = true;
}
if ( ! atr1.Place().equals("Bangalore")) {
System.out.println(" Date "+atr1.Place());
fail = true;
}
if ( ! atr1.version().equals("1.5")) {
System.out.println(" version "+atr1.version());
fail = true;
}
} else {
fail = true;
}
}catch(Exception exp) {
exp.printStackTrace();
fail = true;
}
if (fail) {
System.exit(1);
} else {
System.exit(0);
}
}
}
</console>