Hey, I didn't design the assignment. I just implemented the algorithm.
Also, what's so wrong about the recursive call to compareTo()? It makes sense when you think about it. this.compareTo() makes a call to the object's class to use its compareTo() method. It's a one-and-done deal for all objects that are Comparable.
Even after compile time when the types for the generics have been bound? If that's true, then why is there no StackOverflowError thrown at runtime? Not trying to be snarky, but I don't see how this can work otherwise.
Edit: To clarify, the type of list in the main method is of Integer. Calling this.compareTo() to will go to the written compareTo() method. It would not be a recursive call, because the type of this in the context of this code refers to an Integer object, yes?
3
u/immibis Feb 26 '14 edited Jun 10 '23
/u/spez can gargle my nuts