Illegal direct link

When I try to declare a static array in my program, I get a static direct link error, I'm not sure what I'm doing wrong here ...

static Square fieldGrid [ ] [ ] = new Square [ ROWSIZE ] [ COLSIZE ]; 

this is what i use.

+4
source share
4 answers

Preferred syntax:

  static Square[][] fieldGrid = new Square [ ROWSIZE ] [ COLSIZE ]; 

Also, were you declared and initialized by ROWSIZE and COLSIZE at the time this announcement was created?

+3
source

The ROWSIZE and COLSIZE fields must be initialized before they are used to create a square array. The Java language specification indicates why this restriction exists in place :

These limits are designed to capture, during compilation, cyclical or otherwise distorted initializations.

+2
source

Are strings declared and initialized and colsize before this string? Since they are static, I think the order of the declaration matters.

+1
source

I assume that ROWSIZE and COLSIZE are static final ints, and they are declared after an array declaration. Change the order (first declare and initialize ROWSIZE and COLSIZE), and then use them.

+1
source

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


All Articles