先看下 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.