简体   繁体   中英

Java: IntelliJ idea generated code incorrectly prefixing all Class designations with their Package name

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:

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.

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!

World Class before constructor is added:

package World;

public final class World {

    private final int width;
    private final int height;

    private final Tile[][] terrain;

}

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM