public class Demo1 {
//we will see how we can use Annotations in Java and create Are own annotations
public static void main(String[] args) {
@SuppressWarnings("unchecked")
Cat cat1 = new Cat("kasem");
// System.out.println(cat.getClass().isAnnotationPresent(veryImportant.class));
for(Method meethod : cat1.getClass().getDeclaredMethods() ){
if( meethod.isAnnotationPresent(Runimmedietly.class))
{
meethod.setAccessible(true); // Make the method accessible
meethod.invoke(cat1);// output should hello world
}
}
}
hey guys im trying to invoke the method of the object cat1 but it's giving me this error java: unreported exception java.lang.IllegalAccessException; must be caught or declared to be thrown
package optionalsjJava;
import annotationsJava.*;
@veryImportant
public class Cat {
// @veryImportant //'@veryImportant' not applicable to field
String name;
int i;
public Cat(String name) {
this.name = name;
}
@Runimmedietly
public static void number() {
System.out.println("hello world"); }
i tried to make a try throw exeption, it did remove the error but its giving me a blank output
Aucun commentaire:
Enregistrer un commentaire