The documentation contains the information of what the method should be doing when its implemented. Its a guideline for the implementing class.
On the other hand you should be checking out the source code of SortedMap to find out how the interface is designed. You can get the source code in the src.zip which comes with your JDK installation.
Method body or method implementation is what is inside curly braces after the method declaration (including the braces).
Return type could be a primitive or an object reference.
Interfaces declaration consist of abstract methods declarations plus constant(s) if any. What does it means to declare a method to be abstract? The method must provide a signature (name and 0 or more parameters type), return type and throws if any (optional) and no method body (not implemented) (can't end with curly braces but a semicolon after the "closing parenthesis"): myMethod() or myMethod(int x) are valid method signature examples but then you MUST add the return type: int myMethod(); or void myMethod(int x);
One last thing to remember interface methods are implicitly public and abstract.
What you're seeing is a method named comparator that happens to return a Comparator.
Joined: Nov 11, 2003
Thank you Mohamed & Eduardo! That really clears this up for me!
I reviewed the code in SortedMap as Mohamed suggested, it was very helpful.
For example, when you need a list in your application to store items, declare it like this:
Do not declare it like this:
When you use the first way, it is very easy to switch to another implementation later, because the rest of the application doesn't know what exact implementation of interface List is being used; it only knows (and it only needs to know) that it's a List. For example, you could decide to use a LinkedList instead of an ArrayList:
To the rest of the application, names would still look like a List.