java - Inheritance with generics + collection + method = question -
i have problem generics , collection. java support generics @ compilation level. can't use case b.
{ foo(new hashset<i>()); //case foo(new hashset<c>()); //case b: wrong } void foo(set<i> set){} class c implements i{} interface {}
so how can use function foo set< c > parameter?
thanks.
by changing signature of foo:
void foo(set<? extends i> set){}
you won't able add values set within foo
, you'll able iterate on them or check containment.
Comments
Post a Comment