The Comparable interface has less methods than the Date class. Defining comp as a Comparable rather than a Date narrows down the number of methods available which clarifies the code. This helps decrease the coupling because unnecessary dependencies aren't floating around.
excuse my ignorance here, but I am slightly confused. In relation to the above code:
I was of the opinion, that the JVM during late binding, looks for how the object was created, not the reference, so should not the methods of the Date class, be the available methods, as despite being a Comparable reference type, the object comp was created as a Date. Thus should it not have the methods of the Date class?
To re-iterate Mark's question:
So in effect, what you end up with is a Date object where only the methods defined by the Comparable interface are accessible
I believe it to be that, you end up with a Date type which "IS A" Comparable, of type Date and therefore the methods are of Date class (which by inheritance also include Comparable methods.
Of course, I'm not an expert, but this is my understanding.
be a well encapsulated person, don't expose your privates, unless you public void getWife()!