美文网首页
Android中反射框架mirror

Android中反射框架mirror

作者: adustdu2015 | 来源:发表于2019-11-20 08:55 被阅读0次

http://projetos.vidageek.net/mirror/mirror/

Mirror

Mirror was created to bring light to a simple problem, usually named ReflectionUtil, which is on almost all projects that rely on reflection to do advanced tasks.

Dealing with Java Reflection API is painful. Ask anyone you know that uses reflection and he will tell you it's really unpleasant getting yourself around it.
Take a look at the following code:
//Let's just set a field value. Should be a simple task, right?

//"target" is the object containing the field whose value you want to set.
Field toSet = null;
for (Field f : target.getClass().getDeclaredFields()) {
//Get all fields DECLARED inside the target object class
if (f.getName().equals("field")) {
toSet = f;
}
}
if (toSet != null && (toSet.getModifiers() & Modifier.STATIC) == 0) {
toSet.setAccessible(true);
toSet.set(target, value);
}

相关文章

网友评论

      本文标题:Android中反射框架mirror

      本文链接:https://www.haomeiwen.com/subject/cxvnictx.html