aspose file tools*
The moose likes Java in General and the fly likes JavaBeans spec Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JavaBeans spec" Watch "JavaBeans spec" New topic
Author

JavaBeans spec

Dave Segal
Greenhorn

Joined: Aug 13, 2002
Posts: 20
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

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
And of course, you won't be able to have a getter for both!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Originally posted by Timmy Marks:
And of course, you won't be able to have a getter for both!


Good point!
Dave Segal
Greenhorn

Joined: Aug 13, 2002
Posts: 20
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBeans spec
 
Similar Threads
multiple set() methods on the same property in a POJO
UserType in Hibernate
Sorting Collection
Difference between attribute and parameter
constructor