When I tried to compile my previous java 1.4 code in 1.5 I got this generics Bound mismatch problem. The code is given below
try {
ArrayList simplePrincipals = new ArrayList(
((java.util.Collection) (subject.getPrincipals(Class
.forName("com.efunds.security.jaas.SimplePrincipal")))));
if (simplePrincipals.size() > 0) {
((SimplePrincipal) simplePrincipals.get(0))
.setPermissions(webPerm);
}
}
the error is :
Bound mismatch: The generic method
getPrincipals(Class<T>)of type Subject is not applicable for the arguments(Class<capture#1-. The inferred type
of ?>)capture#1-of ?is not a valid substitute for the bounded parameter<T extends Principal>
If you look at the Javadocs, you’ll see that
getPrincipals()is now defined to take aClass<T extends Principal>— i.e., aClassobject representing a subclass ofPrincipal. Your code has to take this into account, for example, by using theasSubclass()method:Note that your cast to
Collectionas well as most of the parentheses are unnecessary.