Java集合类框架源码分析 之 AttributeList源码解析 【7】

 先看下 AttributeList 类简介,对该类有个概括的全局认识:

/**
 *
 * 代表一个 MBean 的values 列表。
 * <p>Represents a list of values for attributes of an MBean.  See the
 * {@link MBeanServerConnection#getAttributes getAttributes} and
 * {@link MBeanServerConnection#setAttributes setAttributes} methods of
 * {@link MBeanServer} and {@link MBeanServerConnection}.</p>
 *
 * 由于兼容性的原因,可以向{@code AttributeList}中添加不是{@code Attribute}实例的对象,尽管这是非常不鼓励的。
 * 但是,可以将{@code AttributeList}设置为<em>类型安全</em>,这意味着尝试添加非{@code属性}的对象将产生{@code IllegalArgumentException}。
 * 当调用{@link #asList()}方法时,{@code AttributeList}就成为类型安全的了 
 *
 * <p id="type-safe">For compatibility reasons, it is possible, though
 * highly discouraged, to add objects to an {@code AttributeList} that are
 * not instances of {@code Attribute}.  However, an {@code AttributeList}
 * can be made <em>type-safe</em>, which means that an attempt to add
 * an object that is not an {@code Attribute} will produce an {@code
 * IllegalArgumentException}.  An {@code AttributeList} becomes type-safe
 * when the method {@link #asList()} is called on it.</p>
 *
 * @since 1.5
 */
/* 
   * 列举不能扩展ArrayList,而要重新创建创建 AttributeList 的原因。和 RoleList 中类似:
   * 不扩展ArrayList<Role>而单独创建一个RoleList的原因是遗留方法 add(Role)会覆盖 ArrayList 中的add(E),并且 RoleList.add()返回值是void,但是 ArrayList.add()是boolean.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值