本文整理匯總了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);
}