I was trying to make reflection using custom annotation

20 Views Asked by At

i was trying to make reflection using custom annotation and then this exception appeared. so need help regarding this issue,thanks in advance

public class AnnotationTest {

    public static void main(String[] args) {
       
             Cat mycat = new Cat("zeus", 10);
             
            for(Method method:mycat.getClass().getDeclaredMethods())
                
                if(method.isAnnotationPresent(RunImmediately.class)){
                    
                    method.invoke(mycat);
                }
    }

}

method.invoke(mycat); throw illegalaccess exception and i dont know why and how can i fix this

unreported exception java.lang.IllegalAccessException; must be caught or declared to be thrown

0

There are 0 best solutions below