Re: Java 5 Generics Question
- From: Peter Sestoft <sestoft@xxxxxxxxxxx>
- Date: 29 Apr 2005 08:52:51 +0200
Steven <steven.green30@xxxxxxxxxxx> writes:
> I am trying to define an array of vectors.
> For example:
>
> Vector<Object>[] data = new Vector[4];
>
> The preceeding works with warnings.
> Trying:
>
> Vector<Object>[] data = new Vector<Object>[4];
>
> Fails with errors.
> What is the proper way to define an array of Vector<Object> ?
You cannot (in Java 5.0). The reason is that there's no way the array
element assignment check at data[i] = ... could be performed, because
there is no runtime representation of the array element type
Vector<Object>.
Instead use array lists, as in:
ArrayList<Vector<Object>> data = new ArrayList<Vector<Object>>();
WARNING: Technical information, not flame bait, ahead:
This is one of the things that work a little better in
C#/CLI 2.0: the runtime supports exact type instances of generic
types, and therefore you can create an array whose element type is a
type instance of a generic type.
Peter
--
Department of Natural Sciences http://www.dina.kvl.dk/~sestoft/
Royal Veterinary and Agricultural University * Tel +45 3528 2334
Thorvaldsensvej 40, DK-1871 Frederiksberg C, Denmark * Fax +45 3528 2350
.
- References:
- Java 5 Generics Question
- From: Steven
- Java 5 Generics Question
- Prev by Date: Re: Hi I have one web application and i want to get the number of users who are currently accessing the application. Also I want to get the user details of each user, which is stored in a database. How can I do this? Pls help. Getting No: and
- Next by Date: Re: Performance of isDirecory()
- Previous by thread: Java 5 Generics Question
- Next by thread: Preventing Screensaver activation via Java
- Index(es):
Relevant Pages
|
|