为什么 Eclipse 为方法生成参数名称为 arg0,arg1,arg2....?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6303943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:25:06  来源:igfitidea点击:

Why eclipse is generating argument names as arg0,arg1,arg2.... for methods?

eclipsemethodsarguments

提问by Harry Joy

When I try to access some class's method; eclipse gets that method but arguments inside that method are replaced by arg0, arg1, arg2...

当我尝试访问某个类的方法时;eclipse 获取该方法,但该方法中的参数被替换为 arg0、arg1、arg2...

Example:-

例子:-

Suppose I have this method in some class named ReadFile.java

假设我在某个名为 ReadFile.java 的类中有这个方法

@Override
public int readXXX(int start, int end, String xxx) throws IOException {
    return 0;
}

When I try to access that method from an instance of class it shows me as follows:

当我尝试从类的实例访问该方法时,它显示如下:

readFile.readXXX(arg0, arg1, arg2);

It becomes hard to identify what I should pass in argument. The same thing also happens for java methods. i.e. when I implement interface all method under that will be generated but arguments in that methods are arg0, arg1.....

很难确定我应该在参数中传递什么。java方法也会发生同样的事情。即当我实现接口时,将生成该接口下的所有方法,但该方法中的参数是 arg0、arg1.....

Is there any setting I can do prevent this?

有什么设置可以防止这种情况发生吗?

I'm using Eclipse Galelio.

我正在使用 Eclipse Galelio。

采纳答案by dogbane

Eclipse can't work out the arguments because it can't find the source or javadoc attachments.

Eclipse 无法计算参数,因为它找不到源代码或 javadoc 附件。

Make sure your source is attached.

确保您的来源已附加。

To check, click on the method call readXXXand press F3 which should open the method declaration. If the source is not attached, Eclipse will say "Source not found" and will allow you to "Attach Source...".

要检查,请单击方法调用readXXX并按 F3,这将打开方法声明。如果未附加源,Eclipse 将显示“未找到源”并允许您“附加源...”。

回答by javawarrior

Anyone having the same issue, try performing a Project > Clean, this will delete the old class files, and Eclipse will recompile them in debug mode this time. Worked for me in Indigo 3.7.2

任何有同样问题的人,请尝试执行Project > Clean,这将删除旧的类文件,这次 Eclipse 将在调试模式下重新编译它们。在 Indigo 3.7.2 中对我来说有效

回答by Danail Nachev

The problem is that your class files lacks debug information embedded in them. JDT doesn't reparse the source files or the javadoc for dependencies, when building the AST for your project, so it doesn't have idea what the name of the parameter is, even when you are able to open the class and clearly see what are the method names.

问题是您的类文件缺少嵌入其中的调试信息。在为您的项目构建 AST 时,JDT 不会重新解析源文件或依赖项的 javadoc,因此它不知道参数的名称是什么,即使您能够打开类并清楚地看到什么是方法名称。

In order to correct this, you need to recompile your class files with debug information enabled, which makes the class file considerably larger, but unless you are developing for memory-constraint devices, you should be fine.

为了解决这个问题,您需要在启用调试信息的情况下重新编译您的类文件,这会使类文件变得相当大,但除非您正在为内存约束设备进行开发,否则应该没问题。

回答by JesseBoyd

I solved this by going to preferences
Java / Content Assist
On this page under "Sorting and Filtering" I unchecked "Hide proposals not visible in the invocation context" now instead of seeing (arg0, arg1, arg2) etc in autocomplete I see (catalog, schemaPattern, tableNamePattern...)
I am using Spring Tools Suite 3.7.2 which runs on the Eclipse Mars 4.5.1 platform.

我通过转到首选项
Java / Content Assist
在此页面上的“排序和过滤”下解决了这个问题,我现在取消选中“隐藏在调用上下文中不可见的建议”,而不是在自动完成中看到 (arg0, arg1, arg2) 等我看到(目录、schemaPattern、tableNamePattern...)
我使用的是在 Eclipse Mars 4.5.1 平台上运行的 Spring Tools Suite 3.7.2。

回答by gadolf

This linkhelped me to solve this problem.

这个链接帮助我解决了这个问题。

1) Right click on your android.jar and select Properties.

1) 右键单击​​您的 android.jar 并选择属性。

enter image description here

在此处输入图片说明

2) Select Java Source Attachment. Enter the source directory location (you can also use External Folder… to browse to the directory) and click on “Apply“.

2) 选择Java 源附件。输入源目录位置(您也可以使用外部文件夹...浏览目录),然后单击“应用”。

enter image description here

在此处输入图片说明

The code names match the following version numbers, along with API levels and NDK releases provided for convenience:

代码名称与以下版本号以及为方便起见提供的 API 级别和 NDK 版本相匹配:

enter image description here

在此处输入图片说明

回答by LucDaher

for those like me who tried to apply one of our colleagues suggestions and unfortunately hasn't worked, please, give a try to check the option "Add variable attributes to generated class files (used by the debugger)" within Window -> Preferences -> Java + Compiler.

对于像我这样尝试应用我们同事建议但不幸没有奏效的人,请尝试检查窗口 -> 首选项中的选项“将变量属性添加到生成的类文件(由调试器使用)” - > Java + 编译器。

Once you've done that, try to build the project again.

完成后,请尝试再次构建项目。

Cheers.

干杯。