求教高手:向上转型?向下转型?
com.jiveSoftware.forum.database.UserPermissionsCache
中这一句作何解:
ForumPermissions permissions = (ForumPermissions)userPermsCache.get(userID);
我查了 userPermsCache.get(userID) 返回的是一个Cacheable 对象。
虽然ForumPermissions 实现了Cacheable接口,但此处不符合向下 转型的条件。因为向下转型要求 userPermsCache.get(userID)得到的本身是一个ForumPermissions 的实例。
上句出自下面这个函数:
public ForumPermissions get(long forumID, long userID) {
if (!isEnabled()) {
return null;
}
//Get the user perm cache for this forum
LongCache userPermsCache = (LongCache)cache.get(forumID);
ForumPermissions permissions = (ForumPermissions)userPermsCache.get(userID);//问题
if (permissions != null) {
return permissions;
}
else {
return null;
}
}