/* * @(#)Java15.java 1.0 04/03/26 * * You can modify the template of this file in the * directory ..\JCreator\Templates\Template_1\Project_Name.java * * You can also create your own project template by making a new * folder in the directory ..\JCreator\Template\. Use the other * templates as examples. * */ package myprojects.java15; import static java.lang.System.*; import java.lang.annotation.*; import java.lang.reflect.*; @Retention(RetentionPolicy.RUNTIME) @interface Foo{ String bar(); } @Foo(bar="Jensen") public class Java15 { public static void main(String args[]) { //pip("Hans", "Grete", "Knud"); try{ Class c = Java15.class; Foo f = /*(Foo)*/( c.getAnnotation(Foo.class) ); // Why cast?? f = ((AnnotatedElement)c).getAnnotation(Foo.class); // Why not cast?? out.println(f.getClass()); Class jc = Java15.class; Foo ff = jc.getAnnotation(Foo.class); // Why not cast?? X x = new X(); out.print( x.id(7) ); A a = x; out.print( a.id("Gurli") ); }catch(Exception e){ e.printStackTrace(); } } static public @Foo(bar="Hans") void pip(String... a ){ for( String s:a) out.println(s); } } interface A { Y id(Y y); String id(String s); } class X implements A { public Y id(Y y){return y;} public String id(String s){ return "-"+s+"-";} }