Here is the situation...
I have a List<Object>
where I have to pass it around into fairly generic parts of my code. In some parts, the list needs to be sorted.
I will NOT know upfront what type of object is in the list. However, by how this list is used, I am guaranteed that the contract of Comparable
such that each item in the list is of the same type and is able to be compared to each other.
In other words, in some cases, the real type will end up being String
, in other cases, Date
. In yet other cases, something Custom
that implements Comparable<Custom>
.
However, in every case, if the real type is String
, all of the items in the list will be of type String
.
Let me be more specific to improve this question a bit...
Here is a class I am working on:
public class Thing {
private Map<String, List<SourcedValue<Object>>> properties;
}
Then, SourcedValue
is this:
public class SourcedValue<T> {
private T value;
private List<Sources> sources;
}
So, how do you suggest I declare this?