Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

A can full of Beans (Questions)  RSS feed

 
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, well two

Is a bean allowed and equals and hashCode method?
Do all fields in a bean have to have both getters and setters?

I am thinking its okto have equals and hashCode, and that you may wish to represent read only properties, and thus, not having a setter is acceptable.

Cant think of a case for having a setter but not a getter.

G
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cant think of a case for having a setter but not a getter.



This example may lend you a sapling of giant orchard.

Regards,
cmbhatt
[ April 11, 2007: Message edited by: Chandra Bhatt ]
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Is a bean allowed and equals and hashCode method?"

Yes, a bean is just a class, just like any other class, so it can have an equals and hashCode method - in fact it might even be a good idea to provide these methods.

"Do all fields in a bean have to have both getters and setters?"

No, only the fields that you want to expose to the world outside the bean. The bean might have fields that are for internal use only. And indeed you can have read-only properties for which you only provide a getter and no setter.
 
Gavin Tranter
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,
For some reason I find beans Intimidating.
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avoid the Heinz one and you ll be fine
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!