Results 1 to 6 of 6

Thread: Problem in java annotation

  1. #1
    Join Date
    Dec 2009
    Posts
    192

    Problem in java annotation

    Hello,
    I am currently testing the annotations in Java, , but I think this is not working for me. If you have any idea about this then please help me. I think I have not quite understood the concept of the java annotations. I think I do not know or I am confuse why annotations are made in java. If you an explain me this then it would be great. Thanks in advance.

  2. #2
    Join Date
    Dec 2009
    Posts
    296

    Re: Problem in java annotation

    Hello,
    Even I have a same problem with java annotations. This is my code, please check where I am wrong.
    Code:
    Public class conf{
        
        @ description(description ="anyText")
        Public boolean boo = false;
     
        Public Boolean bln = false;
        
        Public byte bytes = 0;
    ...
    This is my annotation
    Code:
    package Configuration;
    
    Public @interface Description {
        String description();
    }
    Any help will be appreciated. Thanks in advance.

  3. #3
    Join Date
    Nov 2009
    Posts
    446

    Re: Problem in java annotation

    Hello,
    Just because you do not specify retention for your endorsement, and by default is the source level is used. This means that your annotation appears only in the source code and not in the *. class, or at runtime via reflection.
    Code:
    @ Retention(RetentionPolicy.RUNTIME)
    Public @interface Description {
        String description();
    }
    According to Java naming conventions, How the packages by a tiny classes and capitalized short the opposite of what you do and I advise you to adopt these conventions.

  4. #4
    Join Date
    Dec 2009
    Posts
    192

    Re: Problem in java annotation

    Hello,
    I tried what you have said, but it does not work for me, I have another question with me. It plays in the loop, but my code
    Code:
    Object [] obj = conf.getClass (). GetAnnotations ();
            System.out.println ("---:"obj.length +);
    I think I need a alternative for this, please if you know any alternative for this then please post back. Thanks in advance.

  5. #5
    Join Date
    Dec 2009
    Posts
    296

    Re: Problem in java annotation

    Hello,
    Here is my test program, please check it
    Code:
    import Configuration.description;
    ...
    Config01 con = new Config01();
    
    Field[] fld = con.getClass().getDeclaredFields();
     
            for(int i =0; i <fld.length; i + +){
                try {
                    Description desc = fld[i].getAnnotation(description.class);
                    if(desc! = null){
                        System.out.System.out.println("!" Annotation "+ desc.Description());
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                }
            }
    ...

  6. #6
    Join Date
    Nov 2009
    Posts
    518

    Re: Problem in java annotation

    Hello,
    I think before you do the loop in your program
    Code:
    Field[] fld = conf.getClass().getDeclaredFields();
    For using annotations you should do
    Code:
    Annotation[] g = conf.getClass().getAnnotations();
    I think this may work, implement this in your code and see if it works. If you need any more help then do post back with the error or the exception you are getting so, it would be easy for us to understand your exact problem.

Similar Threads

  1. Java JDK problem
    By Samara in forum Software Development
    Replies: 6
    Last Post: 19-07-2010, 01:02 PM
  2. Need iPad PDF reader, WITH ANNOTATION
    By Kaustubh m in forum Portable Devices
    Replies: 6
    Last Post: 23-05-2010, 02:06 AM
  3. How to use Override annotation in java?
    By MAHESA in forum Software Development
    Replies: 4
    Last Post: 30-01-2010, 08:25 PM
  4. Java Problem
    By suhjonathan in forum Windows Software
    Replies: 5
    Last Post: 12-11-2009, 09:48 AM
  5. Problem With Java
    By Kusagra in forum Software Development
    Replies: 2
    Last Post: 17-03-2009, 11:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,872,597.33736 seconds with 16 queries