Etienne Neveu commented on LANG-564:
I was also confused by the StrLookup type parameter while browsing the commons-lang 3.0.1 source. Instead of creating a duplicate issue, I thought it would be better to comment here, even though this issue seems to be closed...
I don't see the point of having a generic type parameter on the StrLookup class, if it's not used anywhere. No method / field in StrLookup references this type parameter. IntelliJ IDEA itself reports a warning: "Type parameter 'V' is never used". Moreover, Java generics are not reified, so there is no reliable way to access the type parameter at runtime (and I don't see the point of doing that anyway...).
While the Javadoc tries to clarify the purpose of a StrLookup, the unused type parameter is still confusing, and the client code has to un-necessarily specify type parameters. For example, I have to write:
My best guess is that this type parameter was added when commons-lang was generified, because StringLookup.mapLookup() takes a generified Map. Doing this is not really needed, though: we could remove the <V> type parameter everywhere, and replace the StrLookup.mapLookup()'s Map<String, V> with a Map<String, ?> (which is the same as Map<String, ? extends Object>, but shorter).
I guess it's too late to change this now, due to backward compatibility... But I thought I'd comment just in case it's still possible.
> Improve StrLookup API documentation
> Key: LANG-564
> URL: https://issues.apache.org/jira/browse/LANG-564 > Project: Commons Lang
> Issue Type: Bug
> Components: lang.text.*
> Reporter: Sebb
> Fix For: 3.0
> The API for StrLookup is confused. The class has been partly genericised, but why?
> The Javadoc says the class is for looking up Strings which are indexed by Strings, and this agrees with the method lookup()
> Surely if the class is generic on <V>, the lookup() method should return V, not String?
> Does it make any sense for the class to return anything but a String? If not, then why is the class generic?
> If it does make sense, then lookup() should return V.