热门标签 | 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);
}

推荐阅读
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文详细介绍了Java中org.w3c.dom.Text类的splitText()方法,通过多个代码示例展示了其实际应用。该方法用于将文本节点在指定位置拆分为两个节点,并保持在文档树中。 ... [详细]
  • 本文介绍了Java并发库中的阻塞队列(BlockingQueue)及其典型应用场景。通过具体实例,展示了如何利用LinkedBlockingQueue实现线程间高效、安全的数据传递,并结合线程池和原子类优化性能。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文详细介绍了Akka中的BackoffSupervisor机制,探讨其在处理持久化失败和Actor重启时的应用。通过具体示例,展示了如何配置和使用BackoffSupervisor以实现更细粒度的异常处理。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • XNA 3.0 游戏编程:从 XML 文件加载数据
    本文介绍如何在 XNA 3.0 游戏项目中从 XML 文件加载数据。我们将探讨如何将 XML 数据序列化为二进制文件,并通过内容管道加载到游戏中。此外,还会涉及自定义类型读取器和写入器的实现。 ... [详细]
  • 本文详细介绍了如何构建一个高效的UI管理系统,集中处理UI页面的打开、关闭、层级管理和页面跳转等问题。通过UIManager统一管理外部切换逻辑,实现功能逻辑分散化和代码复用,支持多人协作开发。 ... [详细]
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
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社区 版权所有