热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.commons.lang3.reflect.FieldUtils.writeDeclaredStaticField()方法的使用及代码示例

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

推荐阅读
author-avatar
_西兰花_
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有