help with reflections and annotations in java

Posted by Yonatan on Stack Overflow See other posts from Stack Overflow or by Yonatan
Published on 2010-05-30T17:50:41Z Indexed on 2010/05/30 17:52 UTC
Read the original article Hit count: 254

Filed under:
|
|

Hello Internet !

I'm having trouble with doubling up on my code for no reason other than my own lack of ability to do it more efficiently...

`for (Method curr: all){
        if (curr.isAnnotationPresent(anno)){
            if (anno == Pre.class){
                for (String str : curr.getAnnotation(Pre.class).value()){
                    if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
                        toRun.add(curr);
                    }
                }
            } if (anno == Post.class) {
                for (String str : curr.getAnnotation(Post.class).value()){
                    if (str.equals(method.getName()) && curr.getReturnType() == boolean.class && curr.getParameterTypes().length == 0){
                        toRun.add(curr);
                    }
                }
            }
        }
    }`

anno is a parameter - Class, and Pre and Post are my annotations, both have a value() which is an array of strings.
Of course, this is all due to the fact that i let Eclipse auto fill code that i don't understand yet.

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection