I've been working quite a lot in Java. Although this is part of the university course, we actually have some QAs we need to satisfy, and so the quality of the code matters. Every now and again (more often than not actually), I came across painfully annoying constructs which make the code that much harder to read and write. Like today, I wanted to convert an ArrayList
to a simple array. The array would be used for SOAP (code generated by Apache Axis1). Well... One would think that a simple toArray()
would do it:
1 2 |
ArrayList<T> s = new ArrayList<T>(); return s.toArray(); |
Apparently not. You need something along the lines of:
1 2 |
ArrayList<T> s = new ArrayList<T>(); return (T[]) s.toArray(new T[0]); |
Yeah... The Java Way.