I have a method
<T> void f (Collection<T> c, T t)
Alas, sometimes I need to pass arg Collection as the first argument , but Collection <P> , where P is the predecessor of T , i.e. There is a method P , which returns T . So, how do I change my method to work with Collection <P> and Collection <T> (in the latter case, the getter is personal)?
For instance,
<T> boolean f (Collection<T> c, T t) {
for (T x : c) if (x.equals(t)) return true;
return false;
}
class Z { String a, b; }
I want to use f to search Collection <Z> with a or b
f(Collection<Z> c1 ???searching by a???, "foo")
f(Collection<Z> c2 ???searching by b???, "bar")
T P; , P T ( : Z , ).
Collection <T> .
- : Lisp .