本文整理汇总了Java中org.apache.commons.lang3.reflect.FieldUtils.removeFinalModifier方法的典型用法代码示例。如果您正苦于以下问题:Java FieldUtils.removeFinalModifier方法的具体用法?Java FieldUtils.removeFinalModifier怎么用?Java FieldUtils.removeFinalModifier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.reflect.FieldUtils
的用法示例。
在下文中一共展示了FieldUtils.removeFinalModifier方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
System.setProperty(Constants.LOG4J_LOG_EVENT_FACTORY, TestLogEventFactory.class.getName());
resetLogEventFactory(new TestLogEventFactory());
try {
base.evaluate();
} finally {
System.clearProperty(Constants.LOG4J_LOG_EVENT_FACTORY);
resetLogEventFactory(new DefaultLogEventFactory());
}
}
private void resetLogEventFactory(final LogEventFactory logEventFactory) throws IllegalAccessException {
final Field field = FieldUtils.getField(LoggerConfig.class, "LOG_EVENT_FACTORY", true);
FieldUtils.removeFinalModifier(field, true);
FieldUtils.writeStaticField(field, logEventFactory, false);
}
};
}
示例2: writeStatic
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Write static final field on given class.
*
* @param klass The class.
* @param name The field name.
* @param value The new field value.
* @param <T> Type of value to write.
*/
public static <T> void writeStatic(Class<?> klass, String name, T value) {
try {
Field field = FieldUtils.getField(klass, name, true);
FieldUtils.removeFinalModifier(field);
FieldUtils.writeStaticField(field, value, true);
} catch (Exception ex) {
throw new AssertionError(ex);
}
}
示例3: readPrivateStatic
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Read private static field on given class.
*
* @param klass The class.
* @param name The field name.
* @param <T> Type of returned value.
* @return The field value.
*/
public static <T> T readPrivateStatic(Class<?> klass, String name) {
Field field = FieldUtils.getDeclaredField(klass, name, true);
FieldUtils.removeFinalModifier(field);
try {
@SuppressWarnings("unchecked")
T value = (T) FieldUtils.readStaticField(field, true);
return value;
} catch (IllegalAccessException ex) {
throw new AssertionError(ex);
}
}
示例4: writeStaticFinal
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
/**
* Write value on given static final field.
*
* @param klass The class.
* @param name The field name.
* @param value The new field value.
*/
public static void writeStaticFinal(Class<?> klass, String name, Object value) {
Field field = FieldUtils.getDeclaredField(klass, name, true);
FieldUtils.removeFinalModifier(field);
try {
FieldUtils.writeStaticField(field, value, true);
} catch (IllegalAccessException ex) {
throw new AssertionError(ex);
}
}
示例5: resetClock
import org.apache.commons.lang3.reflect.FieldUtils; //导入方法依赖的package包/类
public static void resetClock(final Class<?> clazz) throws IllegalAccessException {
System.clearProperty(ClockFactory.PROPERTY_NAME);
final Field field = FieldUtils.getField(clazz, "CLOCK", true);
FieldUtils.removeFinalModifier(field, true);
FieldUtils.writeStaticField(field, ClockFactory.getClock(), false);
}