Better type safety in Java collections
Posted
by Paul Tomblin
on Stack Overflow
See other posts from Stack Overflow
or by Paul Tomblin
Published on 2010-03-25T13:55:44Z
Indexed on
2010/03/25
14:03 UTC
Read the original article
Hit count: 386
In my java coding, I often end up with several Map<String,Map<String,foo>>
or Map<String,List<String>>
and then I have trouble remembering which String is which key. I comment the declaration with //Map<capabiltyId,Map<groupId,foo>>
or //Map<groupId,List<capabilityId>
, but it's not the greatest solution. If String wasn't final, I would make new classes CapabilityId extends String
and GroupId extends String
, but I can't. Is there a better way to keep track of which thing is the key and maybe have the compiler enforce it?
© Stack Overflow or respective owner