Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi,
is polymorphism is allowed to used with generics ? if yes can give me a real example real code used polymorphism and what is the difference between ArrayList and Array when we talk about Polymorphism
thanks
Posted 26-Dec-11 22:02pm
hamzah1532
Edited 26-Dec-11 22:12pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Polymorphism is not a phenomena which can be allowed or prohibited. Generics cannot change the situation, because they have nothing to do with polymorphism, because they have nothing to do with inheritance, "virtual" and late binding. Generics are static; any type which can be instantiated during run-time is not generic; it is instantiated into a final type before an instance (object) is constructed. Generic types and final types created out of generics are always the compile-time types. In contrast, all "virtual" behavior and late binging is played on instances and their run-time types, during run-time.
 
This way, generics and polymorphism are parallel phenomena which do not intercept; therefore, they can be freely combined in any thinkable ways.
 
A code sample? There are too many samples around.
 
Here, you can find a conceptual example, good for nearly all object-oriented language: http://en.wikipedia.org/wiki/Subtype_polymorphism#Examples[^].
 
See also http://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29[^].
 
Why knows how many samples you can find in tutorials:
http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html[^],
http://home.cogeco.ca/~ve3ll/jatutor5.htm[^],
http://www.javaworld.com/javaworld/javatips/jw-javatip30.html[^],
http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph.html[^].
 
After all, Google for more.
 
—SA
  Permalink  
Comments
Espen Harlinn at 27-Dec-11 11:30am
   
Good reply - a 5 as usual :)
SAKryukov at 27-Dec-11 11:36am
   
Thank you, Espen.
How have you been lately?
--SA
Espen Harlinn at 27-Dec-11 12:04pm
   
Extreemly busy :(
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Dear Hamzah,
 
Please follow this link it might help you out.
 
http://stackoverflow.com/questions/1814851/c-sharp-generics-and-polymorphism-an-oxymoron[^]
 
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

ye you can create overload of a method
Eg:
public void GetSomething(T a)
{
do something
}
 
public void GetSomething(T a,K b)
{
do something
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 200
1 PIEBALDconsult 150
2 BillWoodruff 148
3 Jochen Arndt 135
4 DamithSL 130
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100