Object generic return value (wrapper class) won't allow for primitive variable assignment

Viewed 67

I have the following getElement object from my node class:

  public T getElement () {
        return element;
    }

In a generic T class I have the following more specialized getElement object to access a linked list that's front is stored in an array:

public T getElement(int col, int row)

Then in another class I have the following variable assignment that uses these objects:

int x = intGrid.getElement(0, 0).getElement();

The above line gives the following error:

The method getElement() is undefined for the type Integer

I can't really show more of the codes details since I'm working with someone else on their code project. Any ideas on how I can alter public T getElement(int col, int row) to fix this? I cannot change the node classes getElement nor can I alter that variable declaration.

1 Answers

I think that intGrid.getElement(0,0) is returning an Integer Java object.

The class Integer does not extends YourNodeClass with the getElement method.

I can't speak more about without seeing your code, but I would recommend to avoid inheritance.

Related