java - Generics and inheritance -
given situation:
class school { public void print(){} } class grade extends school{} class student extends school{} what difference between this
public <e extends school> void somemethod(e someobj) { //now can pass object extends school //and have access methods in school someobj.print(); } and this?
public void somemethod(school someobj) { someobj.print(); }
the obvious difference 1 generic , other not.
and other know generic 1 can capture actual type of argument. of course doesn't make difference in case. imagine if wanted return type exact type of argument, come picture.
Comments
Post a Comment