Saturday, March 27, 2010

Is this an example of polymorphism?

Programmer Question

I'm working on a homework assignment (a project), for which one criterion is that I must make use of polymorphism in a way which noticeably improves the overall quality or functionality of my code.



I made a Hash Table which looks like this:



public class HashTable<E extends Hashable>{
...
}


where Hashable is an interface I made that has a hash() function.



I know that using generics this way improves the quality of my code, since now HashTable can work with pretty much any type I want (instead of just ints or Strings for example). But I'm not sure if it demonstrates polymorphism.



I think it does, because E can be any type that implements Hashable. In other words HashTable is a class which can work with (practically) any type.



But I'm not quite sure - is that polymorphism? Perhaps can I get some clarification as to what exactly polymorphism is?



Thanks in advance!



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails