作者:_西兰花_ | 来源:互联网 | 2024-10-15 14:42
本文整理了Java中org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredStaticField()方法的一
本文整理了Java中org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredStaticField()
方法的一些代码示例,展示了FieldUtils.writeDeclaredStaticField()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FieldUtils.writeDeclaredStaticField()
方法的具体详情如下:
包路径:org.apache.commons.lang3.reflect.FieldUtils
类名称:FieldUtils
方法名:writeDeclaredStaticField
FieldUtils.writeDeclaredStaticField介绍
[英]Writes a named public static Field. Only the specified class will be considered.
[中]写入命名的公共静态字段。只考虑指定的类。
代码示例
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Writes a named {@code public static} {@link Field}. Only the specified class will be considered.
*
* @param cls
* {@link Class} on which the field is to be found
* @param fieldName
* to write
* @param value
* to set
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
public static void writeDeclaredStaticField(final Class> cls, final String fieldName, final Object value) throws IllegalAccessException {
writeDeclaredStaticField(cls, fieldName, value, false);
}
代码示例来源:origin: org.apache.commons/commons-lang3
assertEquals("new", StaticContainer.mutablePublic);
try {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutableProtected", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePackage", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePrivate", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PUBLIC", "new");
fail("Expected IllegalAccessException");
} catch (final IllegalAccessException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PROTECTED", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PACKAGE", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new");
fail("Expected IllegalArgumentException");
} catch (final IllegalArgumentException e) {
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testWriteDeclaredNamedStaticFieldForceAccess() throws Exception {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePublic", "new", true);
assertEquals("new", StaticContainer.mutablePublic);
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutableProtected", "new", true);
assertEquals("new", StaticContainer.getMutableProtected());
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePackage", "new", true);
assertEquals("new", StaticContainer.getMutablePackage());
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "mutablePrivate", "new", true);
assertEquals("new", StaticContainer.getMutablePrivate());
try {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PUBLIC", "new", true);
fail("Expected IllegalAccessException");
} catch (final IllegalAccessException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PROTECTED", "new", true);
fail("Expected IllegalAccessException");
} catch (final IllegalAccessException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PACKAGE", "new", true);
fail("Expected IllegalAccessException");
} catch (final IllegalAccessException e) {
FieldUtils.writeDeclaredStaticField(StaticContainer.class, "IMMUTABLE_PRIVATE", "new", true);
fail("Expected IllegalAccessException");
} catch (final IllegalAccessException e) {
代码示例来源:origin: io.virtdata/virtdata-lib-realer
/**
* Writes a named {@code public static} {@link Field}. Only the specified class will be considered.
*
* @param cls
* {@link Class} on which the field is to be found
* @param fieldName
* to write
* @param value
* to set
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
public static void writeDeclaredStaticField(final Class> cls, final String fieldName, final Object value) throws IllegalAccessException {
writeDeclaredStaticField(cls, fieldName, value, false);
}
代码示例来源:origin: de.knightsoft-net/gwt-commons-lang3
/**
* Writes a named {@code public static} {@link Field}. Only the specified class will be considered.
*
* @param cls
* {@link Class} on which the field is to be found
* @param fieldName
* to write
* @param value
* to set
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
public static void writeDeclaredStaticField(final Class> cls, final String fieldName, final Object value) throws IllegalAccessException {
writeDeclaredStaticField(cls, fieldName, value, false);
}
代码示例来源:origin: io.virtdata/virtdata-lib-curves4
/**
* Writes a named {@code public static} {@link Field}. Only the specified class will be considered.
*
* @param cls
* {@link Class} on which the field is to be found
* @param fieldName
* to write
* @param value
* to set
* @throws IllegalArgumentException
* if {@code cls} is {@code null}, the field name is blank or empty, the field cannot be located or is
* not {@code static}, or {@code value} is not assignable
* @throws IllegalAccessException
* if the field is not {@code public} or is {@code final}
*/
public static void writeDeclaredStaticField(final Class> cls, final String fieldName, final Object value) throws IllegalAccessException {
writeDeclaredStaticField(cls, fieldName, value, false);
}