Java RandomAccess源码总结 RandomAccess源码注释翻译和解析中英文对照版

版本
JDK8(JDK1.8)

RandomAccess接口源码重点
RandomAccess接口是一个标记接口,用于指示实现该接口的列表支持快速随机访问,
如数组实现的列表就支持快速随机访问,而链表实现的列表就不支持快速随机访问

RandomAccess接口源码

/**
 * Marker interface used by {@code List} implementations to indicate that
 * they support fast (generally constant time) random access.  The primary
 * purpose of this interface is to allow generic algorithms to alter their
 * behavior to provide good performance when applied to either random or
 * sequential access lists.
 * List实现使用的标记接口,用于指示它们支持快速(通常为常数时间)随机访问。
 * 此接口的主要目的是允许通用算法在应用于随机或顺序访问列表时改变其行为,以提供良好的性能。
 * 
 *
 * <p>The best algorithms for manipulating random access lists (such as
 * {@code ArrayList}) can produce quadratic behavior when applied to
 * sequential access lists (such as {@code LinkedList}).  Generic list
 * algorithms are encouraged to check whether the given list is an
 * {@code instanceof} this interface before applying an algorithm that would
 * provide poor performance if it were applied to a sequential access list,
 * and to alter their behavior if necessary to guarantee acceptable
 * performance.
 * 操作随机访问列表(如ArrayList)的最佳算法在应用于顺序访问列表(如LinkedList)时会产生二次行为。
 * 鼓励通用列表算法在应用算法之前检查给定列表是否为instanceof此接口,
 * 如果将该算法应用于顺序访问列表,则该算法将提供较差的性能,
 * 并在必要时改变其行为,以确保可接受的性能。
 * 
 * 
 * 
 * 
 * 
 *
 * <p>It is recognized that the distinction between random and sequential
 * access is often fuzzy.  For example, some {@code List} implementations
 * provide asymptotically linear access times if they get huge, but constant
 * access times in practice.  Such a {@code List} implementation
 * should generally implement this interface.  As a rule of thumb, a
 * {@code List} implementation should implement this interface if,
 * for typical instances of the class, this loop:
 * 人们认识到,随机存取和顺序存取之间的区别通常是模糊的。
 * 例如,一些List实现提供了渐近线性的访问时间,如果它们的访问时间很大,但实际上是恒定的。
 * 这种List实现通常应该实现这个接口。
 * 根据经验法则,List实现应该实现这个接口,如果对于类的典型实例,这个循环
 * 
 * 
 * <pre>
 *     for (int i=0, n=list.size(); i &lt; n; i++)
 *         list.get(i);
 * </pre>
 * for (int i=0, n=list.size(); i < n; i++)
 *         list.get(i);
 * 
 * runs faster than this loop:
 * 运行速度比此循环快:
 * <pre>
 *     for (Iterator i=list.iterator(); i.hasNext(); )
 *         i.next();
 * </pre>
 * for (Iterator i=list.iterator(); i.hasNext(); )
 *         i.next();
 *
 * <p>This interface is a member of the
 * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
 * Java Collections Framework</a>.
 *
 * @since 1.4
 */
public interface RandomAccess {
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lolxxs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值