Click here to Skip to main content
11,933,621 members (53,585 online)
Rate this:
Please Sign up or sign in to vote.
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
Posted 26-Dec-11 22:02pm
Edited 26-Dec-11 22:12pm
Rate this: bad
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:[^].

See also[^].

Why knows how many samples you can find in tutorials:[^],[^],[^],[^].

After all, Google for more.

Espen Harlinn 27-Dec-11 11:30am
Good reply - a 5 as usual :)
SAKryukov 27-Dec-11 11:36am
Thank you, Espen.
How have you been lately?
Espen Harlinn 27-Dec-11 12:04pm
Extreemly busy :(
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Dear Hamzah,

Please follow this link it might help you out.[^]

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

ye you can create overload of a method
public void GetSomething(T a)
do something

public void GetSomething(T a,K b)
do something

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 27 Dec 2011
Copyright © CodeProject, 1999-2015
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