Conceptual difference between parametric polymorphism and subtype polymorphism?

sir_thursday

I've tried to read through wikipedia but it's so dense on the subject of polymorphism (specifically related to Java). My understanding is subtype polymorphism is related to subtyping and parametric polymorphism is related to methods being generalized across different objects/classes? What am I missing?

Daniel Kaplan

As the article says,

Parametric polymorphism allows a function or a data type to be written generically, so that it can handle values identically without depending on their type ... Parametric polymorphism is also available in several object-oriented languages, where it often goes under the name "generics" (for example, Java) or "templates" (C++ and D)

So what this means (as an example) is you can make a function that takes a list of somethings, and the function can work no matter what those somethings are. Think of a method that returns the number of elements in a Collection. You can pass in a list of any type of elements, and it will return an answer. You don't have to rewrite the function for every kind of list you pass in.

Some languages employ the idea of subtyping to restrict the range of types that can be used in a particular case of polymorphism. In these languages, subtype polymorphism (sometimes referred to as inclusion polymorphism or dynamic polymorphism[citation needed]) allows a function to be written to take an object of a certain type T, but also work correctly if passed an object that belongs to a type S that is a subtype of T

In other words, you can have a method that takes an Animal as a parameter but you can also pass in a Cat or a Dog into it because Cats and Dogs are animals.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Conceptual difference between parametric polymorphism and subtype polymorphism?

From Dev

Difference between interface and polymorphism

From Dev

Polymorphism, Parametric Polymorphism, Ad Hoc Polymorphism

From Dev

Scala: understanding parametric polymorphism

From Dev

Scala: understanding parametric polymorphism

From Dev

what is the difference between polymorphism and inheritance

From Dev

difference between code polymorphism examples

From Dev

What is the difference between polymorphism and overloading?

From Dev

what is the difference between polymorphism and inheritance

From Java

What is the difference between dynamic and static polymorphism in Java?

From Dev

Difference between std::bind and boost::bind with polymorphism

From Dev

Why is C++ said not to support parametric polymorphism?

From Dev

Confusion with polymorphism: Parametric, Inclusion, Coercion, and Overloading

From Dev

Confusion with polymorphism: Parametric, Inclusion, Coercion, and Overloading

From Dev

Parametric polymorphism breaks when an implicit is expected in Scala

From Dev

operator overloading and polymorphism difference

From Dev

Add SubType information at runtime using Jackson for polymorphism

From Dev

Difference between runtime and compile time polymorphism in c++

From Dev

What is the difference between compile time polymorphism and static binding?

From Dev

What is the difference between compile time polymorphism and static binding?

From Dev

Conflict between separating logic and polymorphism

From Dev

Polymorphism between a parent and a child class

From Dev

Difference between using a structure member and cast a structure pointer when "emulate" polymorphism in C

From Dev

Difference between using a structure member and cast a structure pointer when "emulate" polymorphism in C

From Java

Java static polymorphism (overloading) and inheritance between generics

From Dev

Polymorphism between components in angular2

From Dev

Java static polymorphism (overloading) and inheritance between generics

From Dev

Conceptual difference between Linux and (Free)BSD Kernel

From Dev

Conceptual difference between Linux and (Free)BSD Kernel

Related Related

  1. 1

    Conceptual difference between parametric polymorphism and subtype polymorphism?

  2. 2

    Difference between interface and polymorphism

  3. 3

    Polymorphism, Parametric Polymorphism, Ad Hoc Polymorphism

  4. 4

    Scala: understanding parametric polymorphism

  5. 5

    Scala: understanding parametric polymorphism

  6. 6

    what is the difference between polymorphism and inheritance

  7. 7

    difference between code polymorphism examples

  8. 8

    What is the difference between polymorphism and overloading?

  9. 9

    what is the difference between polymorphism and inheritance

  10. 10

    What is the difference between dynamic and static polymorphism in Java?

  11. 11

    Difference between std::bind and boost::bind with polymorphism

  12. 12

    Why is C++ said not to support parametric polymorphism?

  13. 13

    Confusion with polymorphism: Parametric, Inclusion, Coercion, and Overloading

  14. 14

    Confusion with polymorphism: Parametric, Inclusion, Coercion, and Overloading

  15. 15

    Parametric polymorphism breaks when an implicit is expected in Scala

  16. 16

    operator overloading and polymorphism difference

  17. 17

    Add SubType information at runtime using Jackson for polymorphism

  18. 18

    Difference between runtime and compile time polymorphism in c++

  19. 19

    What is the difference between compile time polymorphism and static binding?

  20. 20

    What is the difference between compile time polymorphism and static binding?

  21. 21

    Conflict between separating logic and polymorphism

  22. 22

    Polymorphism between a parent and a child class

  23. 23

    Difference between using a structure member and cast a structure pointer when "emulate" polymorphism in C

  24. 24

    Difference between using a structure member and cast a structure pointer when "emulate" polymorphism in C

  25. 25

    Java static polymorphism (overloading) and inheritance between generics

  26. 26

    Polymorphism between components in angular2

  27. 27

    Java static polymorphism (overloading) and inheritance between generics

  28. 28

    Conceptual difference between Linux and (Free)BSD Kernel

  29. 29

    Conceptual difference between Linux and (Free)BSD Kernel

HotTag

Archive