I have a class defined as follows:
public class SizeCache<T extends Identifiable> implements Observer {}
Identifiable is simply an interface that defines several methods.
I have a method:
public T put(final T item) {}
This adds the item to the list and is usually called directly with an item of type T, but can come from Observer, so in my Observer I want to make sure that it is of type T.
However, I cannot write this:
public void update(Observable observable, Object data) {
if (data instanceof T) {}
}
As it tells me, I need to use its erasable recognition.
However, when I passed it to Identifiable
Identifiable dataItem = (Identifiable) data;
the put (dataItem) call fails with the put (T) method, which is not applicable to the arguments.
and if I go to the real type T
T dataItem = (T) data;
He warns me of an uncontrollable actor. How to fix it?