Problem with using generic methods
Hello. I'm having a bit of trouble figuring out how to correctly parameterize a function. Here is some sample code to show what I'm trying to do.
interface SampleInterface<T>{
}
//Emulating a set of SampleInterface
interface OtherSampleInterface<Textends SampleInterface><?>>{
publicvoid add(T myStuff);
}
//Just picking string for the heck of it
class SampleInterfaceImplimplements SampleInterface<String>{
}
publicclass GenericsQuestion<E>{
public <Textends SampleInterface><E>>void myFunc(T i){
//!The method add(capture#1-of ? extends SampleInterface<E>) in the type
//OtherSampleInterface<capture#1-of ? extends SampleInterface><E>> is not applicable for the
//arguments (T)
foo.add(i);
}
OtherSampleInterface<?extends SampleInterface<E>> foo;
}
So, as you can see from the error in the comments of the code, it's saying that there aren't appropriate arguments being given to the add function. However, it seems that <Textends SampleInterface><E>>
would be the same as saying <?extends SampleInterface<E>>
right?If it's not the same, then I can't figure out how to get a proper parameter passed into the function, because I can't do something like add(<? extends SampleInterface<E>).
Any help would be greatly appreciated, as I'm pretty much stuck :).

