List <T> cannot contain objects of type Object

Short :
Is it possible to have a class that is not a child Object?

Long
I work with List<T>, which contains interface implementations ( Operation):

public class OperationQueue<T extends Operation> {

    private final List<T> mQueue = new ArrayList<>();
    ...
}

When I look at this list in a loop, I mark each completed operation as null, because I have to maintain the same size, and I cannot use an iterator (it throws ConcurrentModificationException):

for (int i = 0; i < mQueue.size() && !mState.equals(State.PAUSED); i++) {
    mOperation = mQueue.get(i);
    if (mOperation != null) {
        mOperation.run();
    }
    mQueue.set(i, null);
}

When I pause or end a queue, I use:

mQueue.removeAll(Collections.singleton(null));

And Android Studio warns me:

'List<T>' may not contain type objects of type 'Object'

How is this possible? I thought everything is a child Object?

Any help would be greatly appreciated.

+4
3

Object: , Object, : T.

Collections.singleton(null) Ts. Collections.<T>singleton(null); , .

+9

Java Object. - , . , - "", , Object.

, mqueue.removeAll(Collections.singleton(null)) . Collections.singleton(null) mqueue.removeAll(), . , Collections.singleton(null) Set, , "null" - , , , . , removeAll (...) Set, . Set - , Object T.

, - Collections.<T>singleton(null).

+1

<T> java-, , Operation T , Operation,

public class StandardOperation implements Operation{
    ............}

. , Java .

0
source

Source: https://habr.com/ru/post/1619745/


All Articles