In the SCJP Sun Certified Programmer for Java 5(Exam 310-055) Exam Study Guide, the two minute drill in the first chapter(Identifiers (Objective 1.3) )states that methods following the JavaBeans Standards must start with set, get, is, add or remove. Question number 5 of the same chapter's self test asks us to identify method names that follow the JavaBeans standard : A. addSize B. getCust C. deleteRep D. isColorado E. putDimensions
The answer given in the Self Test Answers says the answer is options B and D along with the explanation that 'add' is not standard JavaBeans name prefix. Now isn't there a contradiction here??? Is 'add' a JavaBeans standard prefix or not?
there is no contradiction. The prefix add can also be used. But just add a listener. In such a case the method name must begin with add and ends with word "Listener" and have the same listener type as argument. So a valid method declaration can be:
public void addSomeListener(SomeListener ls);
please look into the K&B book on the page 9 (JavaBean Listener Naming Rules) for further explanation.