Annotations not working

Discussion in 'Plugin Development' started by mrkirby153, Jun 23, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mrkirby153

  2. Offline

    1Rogue

    You need to iterate through the class' methods and then get the annotations of those methods. The annotations you are getting now are class-level annotations such as:

    Code:java
    1. @SomeAnnotation
    2. public class MyClass {
    3.  
    4. //...
    5.  
    6. }
     
  3. Offline

    mrkirby153

    1Rogue

    What? Can I have an example?
     
  4. Offline

    xTigerRebornx

    mrkirby153 You are getting the Class's annotations. If you want the annotations on a Method, you have to loop through the classes Methods and check those annotations.
     
  5. Offline

    Vexil

    mrkirby153 You currently are iterating through all of the annotations that on the class when you should be iterating through the annotations on the methods. You should be looking at something like this:
    Code:java
    1. for (Method method : YourClass.class.getMethods()) {
    2. if (method.isAnnotationPresent(YourAnnotation.class)) {
    3. YourAnnotation yourAnnotation = method.getAnnotation(YourAnnotation.class);
    4. // ...
    5. }
    6. }

    Obviously you should replace YourClass with the class you are getting the methods from and YourAnnotation with the annotation's class.
     
Thread Status:
Not open for further replies.

Share This Page