Re: Array of something
Merciadri Luca wrote:
I am defining a `Tableau' array of `Cell' elements. Tableau and Cell
Show us some code. I don't know what you mean by "a `Tableau' array of `Cell'
are both classes, and some methods over `Tableau' and `Cell' are
Now, my Cell class comprises a State so that to each Cell
instanciation a State is associated, i.e. one can make
Cell myCell = new Cell();
What do you expect to happen as a result of that standalone expression?
Now, for the `Tableau' array, if I need to access a Cell's state, do I need to write, for a `Tableau'
element: myTableau.cell.state? It would mean that a `cell' (of type
Cell) is defined for each `Tableau' element, and that is not the
case. But using myTableau.state would mean that `state' is a variable of
myTableau (of type `Tableau'), which is not the case too, because
state is defined for each Cell element.
Remember that a reference variable can have a value of 'null', and member
variables always start at their "zero" value, which for references is 'null'.
Whatever you do to get a 'Cell', it's clearly 'Cell#state' that you want.
Show us class definitions. You're not speaking Java so it's really, really
hard to figure out what you need help with.
You can have something like this:
public class Tableau
/* p-p */ Cell  cells;
public class Cell
/* p-p */ State state;
Your code to access individual 'Cell' state would be similar to:
import static org.apache.log4j.Logger.getLogger;
public class Processor
/* p-p */ Tableau tableau;
// various setter methods that should give 'tableau' a value
public void process()
if ( tableau == null || tableau.cells == null )
for ( Cell cell : tableau.cells )
if ( cell != null && cell.state != null )
doSomethingWith( cell.state );
I'm ignoring the convention and best practice to use accessor and mutator
(getter and setter) methods instead of raw access to fields. I did not ignore
variable accessibility; I deliberately chose package-private
('/* p-p */') access.
Honi soit qui mal y pense.