Originally posted by Jeroen Wenting:
In that case the Test2 class should implement Comparable and have that test on the Test1 field, not like this with Test1 implementing Comparable.
I disagree. What if Test2s were being ordered by a
String field in Test2? Would you reimplement String-comparison inside Test2 or use String's compareTo() method?
Klaus, I suspect that in retyping those classes here you have managed to fix the problem. In other words, you probably have a typo in the originals. Why do I say this? Because I just ran your code (adding only constructors) and it works beautifully.
The output is 1 ... 9, each on its own line, as expected.
One thought. If you allow duplicate order numbers, you'll get incorrect behavior. You need to initialize returnValue to 0 in Test1 otherwise you return -1 for equal orderNo values. I assumed you didn't have duplicates.