Files
java-core-examples/reflection/output/01-basics.txt
T

33 lines
1.3 KiB
Plaintext

$ java -cp target/classes com.ankurm.reflection.ReflectionBasicsDemo
== 1. Inspect the class ==
class: com.ankurm.reflection.Account
public long balance[]
public void deposit[long]
public String owner[]
private String secret[]
public String[] stack[]
public String toString[]
public static int twice[int]
== 2. Create and call ==
created: Account[alice, 50]
after deposit(25): Account[alice, 75]
== 3. The exceptions you will meet ==
wrong name -> NoSuchMethodException: com.ankurm.reflection.Account.nope()
wrong arg type -> IllegalArgumentException: argument type mismatch
method threw -> InvocationTargetException wrapping java.lang.IllegalArgumentException: over limit: 5000
private, no opt-in -> IllegalAccessException: class com.ankurm.reflection.ReflectionBasicsDemo cannot access a member of class com.ankurm.reflection.Account with modifiers "private"
after setAccessible(true): secret-of-alice
== 4. What reflection adds to the stack ==
direct call:
com.ankurm.reflection.Account.stack
com.ankurm.reflection.ReflectionBasicsDemo.main
through Method.invoke:
com.ankurm.reflection.Account.stack
jdk.internal.reflect.DirectMethodHandleAccessor.invoke
java.lang.reflect.Method.invoke
com.ankurm.reflection.ReflectionBasicsDemo.main