What is the difference between Type and Class?

前端 未结 20 2349
梦谈多话
梦谈多话 2020-11-28 01:00

What makes a type different from class and vice versa?

(In the general language-agnostic sense)

20条回答
  •  长情又很酷
    2020-11-28 01:35

    Types and classes are related but not identical. My take is that classes are used for implementation inheritance, whereas types are used for runtime substitution.

    Here is a link explaining the substitution principle and why subclasses and subtypes are not always the same thing (in Java for example). The wikipedia page on covariance and contravariance has more information on this distinction.

提交回复
热议问题