java note 9:reflex

1.Can u express in a word what reflex is?
it’s a dynamic machanism which obtain field and method of class.
It’s applied to set/get field or method when jvm run-time.

2.which classes are relative with Reflex ?
Class
Field
Method
Constructor
Invoke

3.which classes are associated with Class?

public final class Class<T> implements java.io.Serializable,
                              GenericDeclaration,
                              Type,
                              AnnotatedElement 

Class has implemented:
java.io.Serializable
GenericDeclaration,
Type,
AnnotatedElement.

Class method commonly:
asSubclass:seen as subclass
cast:compulsively
getClassLoader()
getClasses():getAllClasses public as Arrays within class
getDeclaredClasses():include no-public class
forName(String Classname):obtain class object by ClassName
getPackage:
getSimpleName:
getSuperClass:
getInterfaces:
newInstance():create newInstace of class

getField(String name):getField by Field-name public
getFields():getAllField public
getDeclaredField(String name):obtain allField(contain no-public such as private) by name
getDeclaredFields():get all field as Arrays(include no-public such as private)

Mehtod and Field’s method regular
Field.equals(Object o)
Field.set(Object obj,value)
Field.get(Object obj)
Method.invoke(Object obj,InitialnizationArguments args)

Tips:
getDeclaredXXX can obtain private method/field.
and Additional line

Object o = Class.getDeclaredMethod/constructor/Field(methodName,args.class)  
o.setAccessible(true);

If there is explicit permission validation in the source code, and your application cannot obtain it, it is advisable not to waste time reflecting.

Reflection is the soul of frame design.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值