I just saw someone post the following, in a rant on ugly code:
public static
Tuple<ArrayList<ArrayList<ArrayList<String>>>,
ArrayList<ArrayList<ArrayList<String>>>>
split(
ArrayList<ArrayList<ArrayList<String>>> data, [..]);
(layout by me, in a laughable attempt to get this semi-readable)
I’ve been looking for a way to make this look a bit like this (non-functional) code:
TypeParam T = ArrayList<ArrayList<ArrayList<String>>>;
public static Tuple<T,T> split( T data, [..]);
So far the best solution I’ve found is to define a class (in this ex. a class Data), which extends ArrayList<ArrayList<ArrayList<String>>>, which would make the code look like this:
public static Tuple<Data, Data> split( Data data, [..]);
While this method is quite satisfactory, I don’t want to give up on the possibility that there is some way of using generics that I’m missing, and I’m wondering if Java has a way of doing this in an even more aesthetically pleasing way.
Another solution I’m playing with is using an Annotation Processor to fix this for me, however I feel this misses a certain amount of simplicity.
How about
But I agree with @esej that you probably want some class to encapsulate the list-of-lists-of-lists-of-strings data structure.
I am also not sure if you should have
ArrayListhard-coded in there (as opposed to using the interfaceList).