Is not an enclosing class Java

后端 未结 11 2517
轻奢々
轻奢々 2020-11-28 01:41

I\'m trying to make a Tetris game and I\'m getting the compiler error

Shape is not an enclosing class

when I try t

11条回答
  •  醉梦人生
    2020-11-28 02:08

    I have encountered the same problem. I solved by creating an instance for every inner public Class. as for you situation, i suggest you use inheritance other than inner classes.

    public class Shape {
    
        private String shape;
    
        public ZShape zShpae;
        public SShape sShape;
    
        public Shape(){
          int[][] coords =  noShapeCoords;
          shape = "NoShape";
          zShape = new ZShape();
          sShape = new SShape();
        }
    
        class ZShape{
          int[][] coords =  zShapeCoords;
          String shape = "ZShape";
        }
    
        class SShape{
          int[][] coords = sShapeCoords;
          String shape = "SShape";
        }
    
     //etc
    }
    

    then you can new Shape(); and visit ZShape through shape.zShape;

提交回复
热议问题