Effective Java! Use Bounded Wildcards to Increase API Flexibility

Kyle Carter
7 min readMay 21, 2021

Today we take on a bit of a complicated topic but one that, when done correctly, can really make your code much more flexible in its usage. Previously we have talked about how parameterized types are invariant. This means that for two types, TypeA and TypeB, Collection<TypeA> can not be either a subtype or super type of Collection<TypeB>. Making this more concrete, List<String> is not a subtype of List<Object>. This is because any object can go into List<Object> but not any object can go into List<String>. While this may follow logically…

--

--

Kyle Carter

I'm a software architect that has a passion for software design and sharing with those around me.