Java:IntelliJ想法生成的代码错误地为所有Class名称添加了其包名称
I have a package 'World', containing a class 'World' and a class 'Tile'. Class World contains an array of Tiles. When I use IDEA's Generate Constructor function, it produces a constructor like this:
我有一个'世界'包,包含一个'世界'类和一个'Tile'类。 Class World包含一系列Tiles。当我使用IDEA的Generate Constructor函数时,它会生成如下构造函数:
World(int width, int height, World.Tile[][] terrain) {
this.width = width;
this.height = height;
this.terrain = terrain;
}
It immediately highlights "Tile" red and says it can't find that symbol. When I remove the "World." it works as expected.
它立即突出显示“Tile”红色,并表示无法找到该符号。当我删除“世界”。它按预期工作。
What've I screwed up here? I'm running a new installation of IDEA and I've never had this issue before, but I don't think I changed anything that should be causing this. Apologies if this has been asked before I tried searching every permutation of words I could think of!
我搞砸了什么?我正在运行IDEA的新安装,我之前从未遇到过这个问题,但我认为我没有改变任何导致此问题的内容。在我尝试搜索我能想到的每一个单词的排列之前,如果有人问过这个问题,我深表歉意!
World Class before constructor is added:
添加构造函数之前的World Class:
package World;
public final class World {
private final int width;
private final int height;
private final Tile[][] terrain;
}
1 个解决方案
#1
Obicere's comment:
The World class is most likely shadowing the World package. By standard, this is why you use lowercase packages and upper-camel-cased class names.
世界级很可能会影响世界一揽子计划。按照标准,这就是你使用小写包和上层驼峰类名的原因。
Package names can shadow class names--use lowercase package names!
包名称可以影响类名称 - 使用小写包名称!
更多相关文章
- 自定义MapReduce输入格式 - 找不到构造函数
- 关于webview中java调用js函数(解决loadUrl函数没反应)
- 使用Java中的Scala:将函数作为参数传递
- 关于Javascript中声明变量、函数的笔记
- 异步执行多个任务并在JavaScript函数中返回第一个成功的结果