- Generic can be said to be responsible for
safetyin Java - It is used in
methodsorcollection classesthat handle objects of various types, and it is a feature that performstype checkingduring the compilation process - Since the object's
type is checked at compile time, it increases the type safety of objects and reduces the hassle oftype casting- Naturally, 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 added- The 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
- The advantage of this is that there is
- It enables
clearer communication of intentin API design
- Generic is what allows