Skip to content

Instantly share code, notes, and snippets.

@cosminpopescu14
Created August 16, 2020 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosminpopescu14/b9bbe75888614a1e00def7d7f02808cf to your computer and use it in GitHub Desktop.
Save cosminpopescu14/b9bbe75888614a1e00def7d7f02808cf to your computer and use it in GitHub Desktop.
package com.company;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) //can use in method only.
@interface ಠ_ಠ {
public String value() default "ಠ_ಠ";
}
package com.company;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
public class Process {
public static void main(String[] args) {
var obj = Main.class;
for (var m : obj.getDeclaredMethods()) {
processMethodsWithAnnotation(obj, m);
}
}
private static void processMethodsWithAnnotation(Class<Main> obj, java.lang.reflect.Method m) {
if(m.isAnnotationPresent(ಠ_ಠ.class)) {
ಠ_ಠ hmm = m.getAnnotation(ಠ_ಠ.class);
Object[] parameters = { null };
try {
m.invoke( obj.getDeclaredConstructor().newInstance(), parameters);
System.out.println("( ͡° ͜ʖ ͡°)");
} catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
}
}
}
}
@ಠ_ಠ
public static void hmmm(String[] args) {
System.out.println("hmmm");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment