Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Quary about Setter Methord

 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am working on a project in Java my knowledge in java is beginner level.

in my project in EmployeeProfileDTO.java they created setter methord as :
-----------------------------------------------------------------------
public void setEmployeeStartDate(String string) {
employeeStartDate = string;
}
-------------------------------------------------------------------------
My question is why they define String,String why not String employeeStartDate!!!

Please help

Thanks
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by divya sharma:
... My question is why they define String,String why not String employeeStartDate!!!...


That's an excellent question. My preference is to use the same variable name in a setter, along with "this" to set the variable...

In any case, "string" is a terrible name for a variable!
[ September 05, 2007: Message edited by: marc weber ]
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Maybe they don't understand how to use "this". I think that "string" is not very descriptive, and you are asking an excellent question.


would be better if employeeStartDate is a member variable. If employeeStartDate is a local variable, (I think that is doubtful since this is a setter), you could use something like

[ September 05, 2007: Message edited by: Marilyn de Queiroz ]
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow, Marilyn and I are really on the same page today.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eclipse generates names like those when you ask it to generate the unimplemented methods or create a method. Kudos for being offended and wanting to improve them!
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic