Friday, September 26, 2008

Java note: toarray

Because of the implementation of containers, the contained type cannot be instantiated within them. An inconvenient consequence is toArray. There are two ways to call it

Object arr[] = list.toArray();

But it's not easy to change Object[] to Type[].

Type arr[] = new Type[m];

But it would be much better not to have to allocate arr separately.

The next version of Java should really reconsider the implementation of templates.

No comments: