0

I have a generic static inner class inside a generic non-static class. It gives me errors because E cannot be accessed from a static context:

public class List<E>{

public static class InnerClass<E>{

}

How do I fix this? Thanks!

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ezzaral
0

The inner class simulates a heap... It has an array of Cells (a class nested in the inner class) and gives open Cells to instances of List...

So... when you add something to the List, what happens is the List requests a Cell from the static heap:

public void add(E item){

// get open cell
Cell tmpCell = heap.getCell();

...

}

So... the idea is that lots of Lists will be requesting Cells from the heap.

The program is assignment that I am working on, that is why I have an inner class that simulates a heap.

0

You didn't show how Cell is declared, but you mentioned that it was a nested inner class. I would guess that you didn't declare it static. It would need to be static if you want to use it in a static context. Non-static inner classes require an instance of the enclosing class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.