Java Collections: Interfaces and Abstract classes -
Java Collections: Interfaces and Abstract classes -
all collections implements interface collection, these collection have specific abstract hierarchy e.g.
abstractcollection -> abstractlist -> arraylist abstractcollection -> abstractset -> hashsetbut there corresponding interfaces collection, list, set. these interface seem me kind of redundant.
why here ? is convention or there reason implement interface , not extend abstract class.
the interfaces there because it's able assign type variable or parameter without imposing implementation.
for instance if create persistent entity utilize in hibernate, , has collection of things, want assign type of list or set that. hibernate swap out whatever list initialize own, hibernate-specific implementation lazy-loading or whatever else needs to. hibernate developers may not want constrained having extend abstract class.
the abstract class exists convenience implementers. interface contract used clients.
java collections
Comments
Post a Comment