Note that there are some explanatory texts on larger screens.

plurals
  1. POJAVA Wildcard Capture Error with an array of generic stacks
    primarykey
    data
    text
    <pre><code>Stack&lt;?&gt;[] stacks = { new Stack&lt;Bed&gt;(), new Stack&lt;Bookshelves&gt;(), new Stack&lt;Chair&gt;(), new Stack&lt;Desk&gt;(), new Stack&lt;Table&gt;() }; </code></pre> <p>That's the code making the array of stacks. The reason I'm putting them in an array is because it's one of the requirements for the Assignment. The program works without the array.</p> <p>Also, the Stack takes in generics because I had to create my own Stack (also a requirement of the Assignment).</p> <pre><code>while(sc.hasNext()){ temp = sc.nextLine().split(" "); if(temp[0].equals("Bed")){ //beds.push(new Bed(temp[1], temp[2])); stacks[0].push(new Bed(temp[1], temp[2])); }else if(temp[0].equals("Table")){ //tables.push(new Table(Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), Integer.parseInt(temp[3]), temp[4])); stacks[4].push(new Table(Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), Integer.parseInt(temp[3]), temp[4])); }else if(temp[0].equals("Desk")){ //desks.push(new Desk(temp[1],temp[2], Integer.parseInt(temp[3]), Integer.parseInt(temp[4]))); stacks[3].push(new Desk(temp[1],temp[2], Integer.parseInt(temp[3]), Integer.parseInt(temp[4]))); }else if(temp[0].equals("Chair")){ //chairs.push(new Chair(temp[1], temp[2])); stacks[2].push(new Chair(temp[1], temp[2])); }else if(temp[0].equals("Bookshelves")){ //bookshelves.push(new Bookshelves(Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), Integer.parseInt(temp[3]), Integer.parseInt(temp[4]), temp[5])); stacks[1].push(new Bookshelves(Integer.parseInt(temp[1]), Integer.parseInt(temp[2]), Integer.parseInt(temp[3]), Integer.parseInt(temp[4]), temp[5])); }else{ color = temp[0]; } } </code></pre> <p>This code gets the information from the text file and pushes the Objects into the stack.</p> <p>I get an Error saying:</p> <pre><code>push(capture#627 of ?) in Stack&lt;capture#627 of ?&gt; cannot be applied to (Bed) </code></pre> <p>This Error repeats for all the Classes that I have created.</p> <p>The parts commented out is the code that worked before when I made a single stack for each Object.</p> <p>I can't put everything into the array after I have pushed everything into the Stack because points will be taken out for unnecessary intermediate variables.</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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