首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在IntelliJ中看到默认的Java类实现?

如何在IntelliJ中看到默认的Java类实现?
EN

Stack Overflow用户
提问于 2018-12-28 02:34:06
回答 2查看 730关注 0票数 2

有时,我阅读在线javadocs,仍然想知道一个特定的方法是如何工作的。例如,我最近查看了Java-11的ArrayList online javadocforJava-11,我无法判断“删除”方法是缩短了数组的长度,还是在过去有一个元素的地方只留下一个空值。

如何查看IntelliJ中默认Java类的代码实现?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-28 02:40:15

您可以在macOS上使用"Command + click“,或者在Windows或Linux上使用"Ctrl + click”,而游标在方法上以查看它的实现。如果插入符号位于方法名称内,也可以键入“命令/ctrl+ B”,而不是单击。如果它不明确,IntelliJ将允许您从列表中进行选择。

例如,要查看remove的声明,可以编写以下代码:

代码语言:javascript
复制
new ArrayList<String>().remove(1)

然后命令+单击查看其声明:

代码语言:javascript
复制
/**
 * Removes the element at the specified position in this list.
 * Shifts any subsequent elements to the left (subtracts one from their
 * indices).
 *
 * @param index the index of the element to be removed
 * @return the element that was removed from the list
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public E remove(int index) {
    rangeCheck(index);

    modCount++;
    E oldValue = elementData(index);

    int numMoved = size - index - 1;
    if (numMoved > 0)
        System.arraycopy(elementData, index+1, elementData, index,
                         numMoved);
    elementData[--size] = null; // clear to let GC do its work

    return oldValue;
}

或者,您可以右击并选择“转到->声明”:

票数 6
EN

Stack Overflow用户

发布于 2018-12-28 02:47:00

如果您正在使用Mac,⌘+B是查看任何的完整源代码的快捷方式。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53953067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档