Using arrays in enums Java

Part of my Java assignment requires me to create an enumeration that represents four different types of masks (shapes) that cover the squares of the playing field. 3x3 masks in the dimension, while some squares of the 3x3 block are missing (they do not hide the squares on the game board).

1 0 1  //you can think of the 0 as missing squares, and the 1 as the mask
1 1 1
1 1 0

Now I want to bind the binary matrix, as shown above, to each of the four unique masks, using arrays such as int[][], for example:

public enum Mask {
    W([[1,1,0],[1,1,1],[1,0,1]]),
    X([[1,0,1],[1,0,1],[1,1,1]]),
    Y([[0,1,1],[1,1,1],[1,1,0]]),
    Z([[1,0,1],[1,1,1],[1,0,1]]);

My IDE becomes very unhappy when I try to do this, so I am sure that I am missing something in my understanding of enumerations / arrays.

I assume that I cannot initialize an array in an enumeration or something like that?

How to implement this idea?

+4
1

IDE ,

, , .

:

W([[1,1,0],[1,1,1],[1,0,1]]),

, , , ( - ),

W(new int[] { 1, 1 });

. exaplem :

enum Mask {
    W(new int[] { 1, 1 });
    private final int[] myArray;

    private Mask(int[] myArray) {
        this.myArray = myArray;
    }

}
+6

Source: https://habr.com/ru/post/1683339/


All Articles