I am asked by one of colleague about the Throwable class in java API.
As per standard, I do understand, every word ending *able is a interface in java API. There is a industry standard about using such words as Interface names. So, I unknowingly, told him about this as base interface for all the exception and error types in java world. Then he shows me the java file for this class.
My questions:
-
Why java people has choosen this name to be a class. I think this should have been a interface by default?
-
Is this a pattern to use *able words as interface?
-
Is there any other example of class ending with *able?
Regards.
It’s very common for those ‘-able’ names to be interfaces in Java, but there is no official convention for interface naming that I’ve found that suggests that ‘-able’ names should be interface names, though typically that is the case.
Official Java naming conventions can be found here – it’s pretty lean, there really aren’t any restrictions for class or interface naming:
As to your
Throwablequestion, James Gosling once answered why it’s a class rather than an interface, even though the name was more fitting for an interface.Unfortunately, the original article from Sun/Oracle’s site has vanished into the internet ether, so I can only provide indirect attribution:
edit: Since I continue to get upvotes to this question, I found the link to the Sun discussion via the Wayback Machine, here: http://web.archive.org/web/20071013225816/http://java.sun.com/features/2002/03/gosling.html?source=jdc_news&date=20020430