What does it mean for a non generic class to extend a generic class

后端 未结 6 2080
广开言路
广开言路 2021-02-04 10:23
6条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-04 10:26

    Class B is a C.

    C and B are parameterized with an A. (Which means they can have methods and such that use A methods, or the methods of classes that descend from A.)

    A classic use case for this would be that you have a DAO (Data Access Object). You make a generic DAO with some basic methods, like GenericDAO with a generic save method. To make it so other DAOs can extend GenericDAO, you parameterize that class with Entity, and you make sure all your Entitys are saveable.

    Then you have GenericDAO, and a bunch of implementations of that, for example UserDAO extends GenericDAO where User is an entity.

提交回复
热议问题