/** * Returns an immutable list containing only the specified object. * The returned list is serializable. * * @param <T> the class of the objects in the list * @param o the sole object to be stored in the returned list. * @return an immutable list containing only the specified object. * @since 1.3 */ /** * 返回仅包含指定对象的不可变列表。返回的列表是可序列化的。 * 参数:o ― 要存储在返回列表中的唯一对象。 * 返回:仅包含指定对象的不可变列表。 */ publicstatic <T> List<T> singletonList(T o) { returnnewSingletonList<>(o); }
/** * Constructs a list containing the elements of the specified * collection, in the order they are returned by the collection's * iterator. * * @param c the collection whose elements are to be placed into this list * @throws NullPointerException if the specified collection is null */ /** * 构造一个列表,其中包含指定集合的元素,按集合的迭代器返回的顺序排列。 * 参数:c – 其元素要放入此列表中的集合 * 抛出:NullPointerException – 如果指定的集合为 null */ publicArrayList(Collection<? extends E> c) { elementData = c.toArray(); if ((size = elementData.length) != 0) { // c.toArray might (incorrectly) not return Object[] (see 6260652) if (elementData.getClass() != Object[].class) elementData = Arrays.copyOf(elementData, size, Object[].class); } else { // replace with empty array. this.elementData = EMPTY_ELEMENTDATA; } }
/** * Returns an empty list (immutable). This list is serializable. * * <p>This example illustrates the type-safe way to obtain an empty list: * <pre> * List<String> s = Collections.emptyList(); * </pre> * * @implNote * Implementations of this method need not create a separate <tt>List</tt> * object for each call. Using this method is likely to have comparable * cost to using the like-named field. (Unlike this method, the field does * not provide type safety.) * * @param <T> type of elements, if there were any, in the list * @return an empty immutable list * * @see #EMPTY_LIST * @since 1.5 */ /** * 返回一个空列表(不可变)。此列表是可序列化的。 * 此示例说明了获取空列表的类型安全方法: * List<String> s = Collections. emptyList(); * * 返回:空的不可变列表 * 实现 注意: * 此方法的实现不需要为每个调用创建单独的 List 对象。使用此方法的成本可能与使用同名字段的成本相当。(与此方法不同,该字段不提供类型安全) */ @SuppressWarnings("unchecked") publicstaticfinal <T> List<T> emptyList() { return (List<T>) EMPTY_LIST; }
/** * Returns the name of this enum constant, exactly as declared in its * enum declaration. * * <b>Most programmers should use the {@link #toString} method in * preference to this one, as the toString method may return * a more user-friendly name.</b> This method is designed primarily for * use in specialized situations where correctness depends on getting the * exact name, which will not vary from release to release. * * @return the name of this enum constant */ /** * 返回此枚举常量的名称,与其枚举声明中声明的名称完全相同。 大多数程序员应该优先使用该方法 toString , * 而不是这种方法,因为 toString 方法可能会返回更用户友好的名称。 此方法主要用于正确性取决于获取确切名称的特殊情况,该名称不会因版本而异。 * 返回:此枚举常量的名称 */ publicfinal String name() { return name; }
Colorcolor= Color.RED; System.out.println(color.name()); // 输出: RED