What does the error T does not match T mean in my Java code?

  • Context: Comp Sci 
  • Thread starter Thread starter magnifik
  • Start date Start date
  • Tags Tags
    Array Java List
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
magnifik
Messages
350
Reaction score
0
I am getting compilation errors in the following segment of my code:

_underlyingStorage was declared in the following way: private T[] _underlyingStorage = (T[]) new Object[128];

public T next() {
_currentIndex++;
if(_underlyingStorage[_currentIndex] == _underlyingStorage[_numElements-1])
_underlyingStorage[_currentIndex] = _underlyingStorage[0];
return _underlyingStorage[_currentIndex];
}

the error I'm getting makes no sense to me.. it says that T does not match T. what's happening here?
 
Physics news on Phys.org
Where are you getting the error at? I entered everything you had into a class, but I'm not getting any error.
 
magnifik said:
the error I'm getting makes no sense to me.. it says that T does not match T. what's happening here?
Errors reported by the compiler and the runtime are usually very precisely worded, containing a very literal description of a problem in your program and where that problem occurs.

If you aren't yet experienced enough to extract this information from an error, you should copy it verbatim when you ask for others to help. (also, there's probably a line number involved. It would help if you point out which line of your code it refers to)