Hi all,
I am currently working on a project based on the
struts 2 framework with my colleagues and we were discussing something about overloading setters. Nevertheless, this
thread is more related to
Java Beans, rather than the struts framework. I am not very experienced in Java Beans and I'd like to get some advices on it.
Suppose we have a pseudo bean with enum variables, getters and setters:
We want to use this bean to collect data from a html form, but we realise there are some casting problems - submitted data from the form is in type of
String rather than being automatically casted into MyEnum.
So I suggested to overload the setter:
I've tried building and running on my local environment - it seems to work. My colleague could not get that run perfectly and also complained that this is a bad bean practice. He said that if we overload a setter method with different number of parameters, that'll be ok, but if we overload the setter method with the same number of parameters but of different types, this will break things.
I am not very experienced in beans. May be this is a bad practice but I believe my overloading should work, shouldn't it? I'd like to hear views from others.