Closed janlukasik closed 7 years ago
Hi, Podam uses a setter, which is defined in the most specific class (the latest in an inheritance chain). You can implement your own ClassInfoStrategy, if you want to select setters yourself. And what setter do you want to select in your case?
Hi, thanks for the quick reply. I don't have a class used in project right now, but basically, having two setters as below:
public void setField(Integer field) {
this.field = field;
}
and
public void setField(String field) {
this.field = Integer.parseInt(field);
}
I would like to use the first one. Thanks for the hint - I will read more about the ClassInfoStrategy.
Well, one should never write the code like in second setter. This will fuck up not only Podam, but also inattentive developers. This is actually a good thing that Podam fails in such use case as it helps developers to fix this issue with their code.
Probably it is a silly question but what is wrong with second setter? Not sure if it makes a diffierence, probably not - the purpose of the class above is to solely test a code.
Here field is declared as a string, while in reality it's expecting an integer. And every time anyone will pass there string, which is not a number, they will get NumberFormatException, which is not even declared in the method signature. This requires other developers to read sources to be sure what they are doing makes sense. And what is even a gain here?
However, if we are speaking about, for example, String/URL ambiguity - this is a valid problem.
I see. Thank you very much for the hint and clarifications - seems I have to review the project code to answer your question - but as far as I remember the setters looked as I presented above.
Hi After the code review I came to the conclusion that the second setter was a mistake. As you mentioned - there is no gain to have it. Thank you.
Not at all.
I'm using a class with overloaded setter method in my project. Could you please tell me how Podam selects a setter to be used? Is there a way - having two or more setters - choose the one that I would like to use?