Created
August 16, 2020 06:04
-
-
Save cosminpopescu14/b9bbe75888614a1e00def7d7f02808cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "ಠ_ಠ"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ಠ_ಠ | |
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