What is the difference between Type and Class?

前端 未结 20 2303
梦谈多话
梦谈多话 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:10

    Interesting question. I think aku's answer is spot on. Take the java ArrayList class as an example

    public class ArrayList extends AbstractList
        implements List, RandomAccess, Cloneable, java.io.Serializable
    

    An instance of the ArrayList class is said to be of type of every superclass it extends and every interface it implements. Therefore, an instance of the ArrayList class has a type ArrayList, RandomAccess, Cloneable, and so forth. In other words, values (or instances) belong to one or more types, classes define what these types are.

提交回复
热议问题