Re: generics and arrays and multi-class collections
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Sep 2007 07:08:06 GMT
On Sat, 29 Sep 2007 22:36:13 -0700, SadRed <cardinal_ring@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 Glossary
http://mindprod.com
.
- Follow-Ups:
- Re: generics and arrays and multi-class collections
- From: SadRed
- Re: generics and arrays and multi-class collections
- 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
- generics and arrays and multi-class collections
- Prev by Date: Re: notifying particular thread to wake up.
- Next by Date: Re: Get Free E-Books!!
- 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
|