Generic
Generic can be said to be responsible for
safetyin JavaIt is used in
methodsorcollection classesthat handle objects of various types, and it is a feature that performstype checkingduring the compilation processSince the object's
type is checked at compile time, it increases the type safety of objects and reduces the hassle oftype castingNaturally, the code also becomes more concise
ex)
Generic is what allows
only specific objects to be added to a Collection, or only objects with characteristics of a specific class to be addedThe advantage of this is that there is
no need to implement separate logic inside the collection to verify whether the incoming value is the value you want
It enables
clearer communication of intentin API design
Last updated