java - What Exception is thrown when an implementation breaks its interface's contract? -


through amount of debugging (i not wish repeat) i've found circumstance can arrived @ if 1 of objects given comparator breaks interface's contract (namely comparator compare(a, a) returns non-zero value).

what kind of exception should throw?

i thought take inspiration treemap, takes comparator, acts bizarrely (not throwing exception) if give nonsense comparator.

the common way use java.lang.illegalargumentexception:

throw new illegalargumentexception("one of objects given breaks comparators interface contract "); 

you can take @ documentation:

thrown indicate method has been passed illegal or inappropriate argument.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -