• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

y to implement serializable in getter & setter ?

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we implement serializable in getter and setter ???
 
Shubha Sridhar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data you are going to set or get using getter or setter method some times may need to pass through network from one remote to another remote system.Serializable is property that allows you to write the data or the object state into an output stream and fetch it back from there...
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we implement serializable in getter and setter ???

Can you please explain your question more clearly?

Getters and setters are methods. You cannot implement interface Serializable in a method. Is your question about what Serializable means?

Or did you mean to ask why in a Java Bean (which is a class that has getter and setter methods) you should implement Serializable? If you meant that, that's because it's one of the criteria which makes a class a Java Bean. Wikipedia says:

"In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

* The class should be serializable (able to persistently save and restore its state)
* It should have a no-argument constructor
* Its properties should be accessed using get, set and other methods following a standard naming convention
* It should contain any required event-handling methods"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"y" is not a word. Please use real words such as "why" when posting. Please read this for more information.
[ February 22, 2007: Message edited by: Ernest Friedman-Hill ]
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that the Wikipedia article is wrong at least about the getXXX() setXXX() naming convention being required.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that the Wikipedia article is wrong at least about the getXXX() setXXX() naming convention being required.

How so? The rules a bean must follow are mentioned here, and nothing about that naming convention sounds optional to me.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it is because for booleans you can use the isXXX method.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic