Note that there are some explanatory texts on larger screens.

plurals
  1. POConstructors for arrays in Java
    primarykey
    data
    text
    <p>I am working on a problem where I need to have a class that is represented by a boolean array. This is the only constructor I have.</p> <pre><code>private boolean[] integerSet; private static final int ARRAY_LENGTH = 101; // set will always be 0-100 // no argument constructor // creates set filled with default value false public Exercise_8_13() { integerSet = new boolean[ARRAY_LENGTH]; } </code></pre> <p>The methods I am writing after this all give the error "The type of an expression must be an array type, but it is resolved to Exercise_8_13". The methods are taking arguments of type Exercise_8_13.</p> <p>Do I need to make another type of constructor to prevent the error? Or is it something in the constructor I have? The question only specified that a no-argument constructor had to be created.</p> <p>I have looked at this question which seems to be a similar problem but I still do not understand the solution. <a href="https://stackoverflow.com/questions/7369503/the-type-of-an-expression-must-be-an-array-type-but-it-is-resolved-to-object">The type of an expression must be an array type, but it is resolved to Object</a></p> <p>Here is an example method, the error is triggered on a[counter], b[counter], and both instances of intersectionSet[counter].</p> <pre><code> public static void intersection(Exercise_8_13 a, Exercise_8_13 b) { Exercise_8_13 intersectionSet = new Exercise_8_13(); for (int counter = 0; counter &lt; ARRAY_LENGTH; counter++) { if ((a[counter] = false) || (b[counter = false])) { intersectionSet[counter] = false; } else { intersectionSet[counter] = true; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload