Topic: java泛型问题 |
Print this page |
1.java泛型问题 | Copy to clipboard |
Posted by: hafocus Posted on: 2007-05-08 17:06 一直用jdk1.4,最近用了5,对泛型不是很了解,大家说说! 我在web应用中 ArrayList<User> users; users = (ArrayList<User> User.getAllUsers(); session.setAttribute("shoujianren", users); 但是取值时 ArrayList<User> users = (ArrayList<User>(session.getAttribute("shoujianren")); 有个警告,说 Type safety: The cast from Object to ArrayList<User> is actually checking against the erased type ArrayList 我已经数据类型转换了阿? |
2.Re:java泛型问题 [Re: hafocus] | Copy to clipboard |
Posted by: snowbug Posted on: 2007-05-17 06:00 session 里的 attribute 是向上 cast 成 Object 类型保存的。取出时也是 Object 类。你的转型在 session.setAttribute() 的时候就丢失了。 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |