• Post Reply Bookmark Topic Watch Topic
  • New Topic

Call alot of setters from another class  RSS feed

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have alot of lines that call setter methods. Anyway to put this all in another class and call it so I dont have to list all these in my current class?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This way works if and only if your request parameter is as same as your POJO field name.

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ricky's method works. He uses the reflection API to find setter methods that match the names of the properties you want to set and calls them. That's OK, but it is a low-level approach. You could also use the Java Beans API to do this. Example:

Call it like this:

[ August 14, 2007: Message edited by: Jesper Young ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!