But, importantly, I don't actually care how these objects are ordered.
This is exactly what Guava's Ordering.arbitrary()
will do:
Returns an arbitrary ordering over all objects, for which compare(a, b) == 0
implies a == b
(identity equality). There is no meaning whatsoever to the order imposed, but it is constant for the life of the VM.
However, it specifically doesn't support your requirement for:
I would like to sort this list so that the ordering is the same each time I compile my code.
For that, you'll need to give your objects some kind of identifying state. This could be name, an index of construction order or an explicit order. There is no general way to carry the "same" order across runs without knowing more about your code.
If the "same" order means the order in which your algorithm produced its results, make the Map
one that preserves the order of insertion, rather than sorting afterwards. That will give you a deterministic order based on your code's behaviour.