When would you not use Generic Collections?

前端 未结 8 1815
醉酒成梦
醉酒成梦 2021-01-19 00:57

The advantage of using generics is that it increases the type safety - you can only put in the correct type of thing, and you get out the correct type without requiring a ca

8条回答
  •  面向向阳花
    2021-01-19 01:27

    One thing I think you need to consider is that a generic collection is not always a drop in replacement for a non-generic collection. For example, Dictionary can not simply be plugged in for an instance of Hashtable. They have very different behavior in a number of scenarios that can and will break programs. Switching between these two collections forces a good programmer to examine the use cases to ensure the differences do not bite them.

提交回复
热议问题