Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBeans spec

 
Dave Segal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do overloaded signatures on java bean properties violate the spec? ie:

public void setProp (String prop) {this.prop = new Prop(string));}
public void setProp (Prop prop) {this.prop = prop; }

If I do this, must I use BeanUtil to specify which setter to use, or does the spec state that reflective clients take the signature into acccount when selecting a setter?

Thanks,
Dave
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My recollection is that the spec doesn't mention overloading explicitly, but it does say that a matching get/set pair will be recognized. Therefore if there's a getter as well as a setter for only one of the overloads, theoretically you should be fine. I can't say what will happen in practice.
 
Timmy Marks
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And of course, you won't be able to have a getter for both!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timmy Marks:
And of course, you won't be able to have a getter for both!


Good point!
 
Dave Segal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will test this out and let you know (prob won't be until next week though.)

I'm encountering the problem in Hibernate. I can map to a bean property as long as there is only one set method for that property. I can use either a String or a custom class as my argument, but I can't include both signatures on the same property. I couldn't find anything in the spec that prohibits the use of multiple setters with different arguments, so I am starting to think that the restriction is in Hibernate.

Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic