boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - 问个 Generic 的问题
相关主题
如何定义这样的数组?
问一个Java的问题,关于create generic array
extending generic class , but not mentioning its parameterized type?
Generics应该怎么得到它的class?
如何造Array of Generic Type
[转载] Java 1.5 Generic 问题
An interesting thing about java generics-do not laugh at me if u think it too basic
请问有没有generic的array
Interview的人问我最新java 版本是多少
菜鸟问关于Java Programming的问题
相关话题的讨论汇总
话题: list话题: string话题: biglist话题: generic话题: newlist
进入Java版参与讨论
1 (共1页)
c*******e
发帖数: 290
1
List bigList = new ArrayList();
List smallList = new ArrayList()
List newList = ListUtils.subtract(bigList, smallList);
List[] samples = {bigList, newList};
后面两行同样的问题,都 warning 说没有 parametrized. 那个 subtract 是因为
ListUtils 里面只返回 raw type List. 最后那行是因为直接定义数组比较简洁。
这种情况,只有用 @SuppressWarnings 吗?
g*****g
发帖数: 34805
2
subtract should have parametric signature like
static List subtract()
The second one you can use
List[]

【在 c*******e 的大作中提到】
: List bigList = new ArrayList();
: List smallList = new ArrayList()
: List newList = ListUtils.subtract(bigList, smallList);
: List[] samples = {bigList, newList};
: 后面两行同样的问题,都 warning 说没有 parametrized. 那个 subtract 是因为
: ListUtils 里面只返回 raw type List. 最后那行是因为直接定义数组比较简洁。
: 这种情况,只有用 @SuppressWarnings 吗?

c*******e
发帖数: 290
3
奇怪的是,common.apaches library 的一些 utility classes, 都不是用 generics,
所以出现这个 warning. 难道是因为它太老?
http://commons.apache.org/proper/commons-collections/javadocs/a
第二个问题,如果改为:
List[] samples = {bigList, newList};
就出错,提示 “you cannot create a generic array of List”. 可能是因
为这种 syntax ={,,,} 定义一个 primitive array, 其不支持 generics.所以,这种
快捷方式 {} 定义数组,只能使用原始的数据类型。

【在 g*****g 的大作中提到】
: subtract should have parametric signature like
: static List subtract()
: The second one you can use
: List[]

x****d
发帖数: 1766
4
1, too old, it is not updated for long time, you can redo it in generic if
your company used it a lot, but in some company that means get legal
department involved to review the licence, pain in the butt.
2, public T[] toArray(T[] a), but as you said, not simple as your code.
s******e
发帖数: 493
5
coz java array is reifiable.

,

【在 c*******e 的大作中提到】
: 奇怪的是,common.apaches library 的一些 utility classes, 都不是用 generics,
: 所以出现这个 warning. 难道是因为它太老?
: http://commons.apache.org/proper/commons-collections/javadocs/a
: 第二个问题,如果改为:
: List[] samples = {bigList, newList};
: 就出错,提示 “you cannot create a generic array of List”. 可能是因
: 为这种 syntax ={,,,} 定义一个 primitive array, 其不支持 generics.所以,这种
: 快捷方式 {} 定义数组,只能使用原始的数据类型。

x****d
发帖数: 1766
6
List is non-reifiable same as List, only raw type and List is
reifiable.
Effective Java Item 25: Prefer lists to arrays talks about this
situation.
1 (共1页)
进入Java版参与讨论
相关主题
菜鸟问关于Java Programming的问题
generics这样改对马?
how to copy an Object?
What do you think about AOP?
Sun的JDK 1.5有什么新特点吗?
我想把一个Arraylist转成String[]
Re: j2se5.0 anybody tried
请帮忙看看这个编译错误
问一个generic的问题吧
再问generic问题:tomcat编译错误
相关话题的讨论汇总
话题: list话题: string话题: biglist话题: generic话题: newlist