警告!!

bandit001 2006-12-11 09:16:03
Type safety: The method set(Object) belongs to the raw type ThreadLocal. References to generic type ThreadLocal<T> should be parameterized
这个警告怎么消除!!谢谢!!!
...全文
199 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bandit001 2006-12-13
  • 打赏
  • 举报
回复
Type safety: The cast from Object to Vector<ShopCart> is actually checking against the erased type Vector
welshem 2006-12-13
  • 打赏
  • 举报
回复
Vector shopCartList=(Vector)session.getAttribute(Constants.SHOPCART_KEY);
if (shopCartList==null) {
shopCartList = new Vector();
}
改为
Vector<ShopCart> shopCartList=(Vector<ShopCart>)session.getAttribute(Constants.SHOPCART_KEY);
if (shopCartList==null) {
shopCartList = new Vector<ShopCart>();
}
bandit001 2006-12-13
  • 打赏
  • 举报
回复
Type safety: The method addElement(Object) belongs to the raw type Vector. References to generic type Vector<E> should be parameterized

怎么改,我以前在eclipse3.1里是正常的,现在eclipse3.2+myeclipse5.0就出现很多类似问题
谢谢!!!
bandit001 2006-12-13
  • 打赏
  • 举报
回复

package cn.com.shoppingonline;

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;

public final class BuyAction extends Action{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {

DynaActionForm productIdForm = (DynaActionForm) form;
Integer productId = (Integer)productIdForm.get("productId");

HttpSession session = request.getSession();
String PageForward;
boolean bBought=false;

ShopCart compareShopCart = new ShopCart();
Vector shopCartList=(Vector)session.getAttribute(Constants.SHOPCART_KEY);
if (shopCartList==null) {
shopCartList = new Vector();
}
/*

*/
ActionMessages errors = new ActionMessages();
if(shopCartList != null ){
for(int i = 0;i < shopCartList.size();i++){
compareShopCart = (ShopCart)shopCartList.get(i);
if (compareShopCart.getProduct().getId()==productId.intValue()){
bBought=true;
}
}
}
/*

*/
if (!bBought){
Product product=new DbOperate().getProduct(productId.intValue());

ShopCart shopCart = new ShopCart();
shopCart.setProduct(product);
shopCart.setPrice(product.getSaleprice());
shopCart.setCount(1);
shopCartList.addElement(shopCart);
session.setAttribute(Constants.SHOPCART_KEY,shopCartList);
PageForward="toShopCart";
}
else{
errors.add(ActionMessages.GLOBAL_MESSAGE,
new ActionMessage("errors.alreadyBought"));
if (!errors.isEmpty()) {
saveErrors(request, errors);
}
PageForward="toWrong";
}
return (mapping.findForward(PageForward));
}
}
welshem 2006-12-12
  • 打赏
  • 举报
回复
在你定义Vector等变量时就用下面的格式声明其中放置的类型以便编辑器检查
Vector<Object> list=new Vector<Object>();
<>之中是要addElement的真实元素类型
bandit001 2006-12-12
  • 打赏
  • 举报
回复
自己顶
bandit001 2006-12-12
  • 打赏
  • 举报
回复
自己顶
bandit001 2006-12-11
  • 打赏
  • 举报
回复
Type safety: The method addElement(Object) belongs to the raw type Vector. References to generic type Vector<E> should be parameterized
这个也是

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧