Re: generics and arrays and multi-class collections
- From: SadRed <cardinal_ring@xxxxxxxxxxx>
- Date: Sun, 30 Sep 2007 03:30:30 -0700
On Sep 30, 4:08 pm, Roedy Green <see_webs...@xxxxxxxxxxxxxxxxxxxx>
wrote:
On Sat, 29 Sep 2007 22:36:13 -0700, SadRed <cardinal_r...@xxxxxxxxxxx>
wrote, quoted or indirectly quoted someone who said :
What part of the source do you refer?
code like this:
public <T> T[] toArray(T[] a) {
if (a.length < size)
// Make a new array of a's runtime type, but my contents:
return (T[]) Arrays.copyOf(elementData, size,
a.getClass());
System.arraycopy(elementData, 0, a, 0, size);
if (a.length > size)
a[size] = null;
return a;
}
If you write code like that I think you will get warnings.
It has been a while. I was trying to allocate arrays of the given
generic type, and was baffled. I used code similar to what I found in
Sun's collections and to my surprise discovered it generated warning
messages. I asked about it on the newsgroups and the wise ones
assured me this was indeed a limitation of Java's genericity design.
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com
Yes. The code you've mentioned does generate an *unchecked* warning.
Sun has just ignored it just like us. :):)
.
- Follow-Ups:
- References:
- generics and arrays and multi-class collections
- From: xen
- Re: generics and arrays and multi-class collections
- From: Roedy Green
- Re: generics and arrays and multi-class collections
- From: SadRed
- Re: generics and arrays and multi-class collections
- From: Roedy Green
- generics and arrays and multi-class collections
- Prev by Date: Re: Cannot find symbol java error (newbie question)
- Next by Date: Singly Linked LIst and Objects Newbie Question
- Previous by thread: Re: generics and arrays and multi-class collections
- Next by thread: Re: generics and arrays and multi-class collections
- Index(es):
Relevant Pages
|