Hi, I got help from an old post and I got it done. Thank you.
On Aug 27, 2:02 pm, Guillermo <[email protected]> wrote: > Hi all, > I dont really understand annotations and I dont know what I am doing > wrong with this lab, the code is the following: > > "RequestForEnhancement.java" > > import java.lang.annotation.*; > > @Retention(RetentionPolicy.RUNTIME) > @Target(ElementType.METHOD) > > public @interface RequestForEnhancement { > int id(); > String synopsis(); > String engineer() default "[unassigned]"; > String date() default "[unimplemented]";} > > ******************************************************************************************* > > "AnnotationImplementation.java" > > import java.util.Date; > > public class AnnotationImplementation { > int id; > String synopsis; > String engineer; > Date date; > > �...@requestforenhancement( > id = 2868724, > synopsis = "Enable time-travel", > engineer = "Mr. Peabody", > date = "4/1/3007") > > public int getId(){ > return id; > } > public String getSynopsis(){ > return synopsis; > } > public String getEngineer(){ > return engineer; > } > public Date getDate(){ > return date; > }} > > ******************************************************************************** > "MyOwnAnnotationExample.java" > > import java.lang.annotation.*; > > public class MyOwnAnnotationExample { > > AnnotationImplementation ai; > > public MyOwnAnnotationExample(){ > ai=new AnnotationImplementation(); > } > > public void printAnnotations() { > Class c = ai.getClass(); > Annotation[] annotations = c.getAnnotations(); > int numberOfAnnotations = annotations.length; > System.out.println("Class " + c.getName() + " has " + > numberOfAnnotations + " annotations"); > > for (int i = 0 ; i < numberOfAnnotations; i++) { > System.out.println("Annotation " + i + ": " + annotations > [i] + > ", type" + annotations[i].annotationType().getName > ()); > } > } > > public static void main(String[] args) { > MyOwnAnnotationExample moae = new MyOwnAnnotationExample(); > moae.printAnnotations(); > } > > } > > *********************************************************** > > The resul when build and run is: > > run: > Class AnnotationImplementation has 0 annotations > BUILD SUCCESSFUL (total time: 2 seconds) > > Am I annotating a method, if so, why the result says 0 annotations, > what´s wrong > > Thank you. --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en -~----------~----~----~----~------~----~------~--~---
