| Author |
Bean property must has both getter / setter ?
|
Vince Hon
Ranch Hand
Joined: Feb 11, 2003
Posts: 117
|
|
In HFB P.368 2 The thing to the right of the dot MUST be a Map Key or a /*bean property*/
And in HFB P.350, the Bean law states that 4) The property name and type are derived from the getters and setters and NOT from a member in the class.
That mean if I have a bean called MyBean and property called pp: int, the MyBean class must have BOTH getter and setter for "pp". In HFB P.15 Question 15 Will options A, B, D, E always print "nothing" since there are no those property (because no setter methods) ?
|
Vince Hon<br /> <br />SCJP 1.4 | SCWCD | SCBCD <br /><a href="http://vincehon.homeip.net:8000/VJW" target="_blank" rel="nofollow">http://vincehon.homeip.net:8000/VJW</a>
|
 |
Narendra Dhande
Ranch Hand
Joined: Dec 04, 2004
Posts: 950
|
|
Hi, It is not necessary to have both getter and setter methods. In the above case, the value can be assigned at the time of initialization. thanks
|
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
|
 |
Vince Hon
Ranch Hand
Joined: Feb 11, 2003
Posts: 117
|
|
Thanks. However, this qoute
And in HFB P.350, the Bean law states that 4) The property name and type are derived from the getters and setters and NOT from a member in the class.
The "bean requires both getter/setter" is apply to the <jsp:setProperty../> but not the EL ?
|
 |
Narendra Dhande
Ranch Hand
Joined: Dec 04, 2004
Posts: 950
|
|
Hi, I think the getter/setter not only apply to the setProperty but for the EL also. When using . or [] it calls the getter method. In general if no setter , then the property is read-only. If only getter is definde, you can not update the property using setProperty. If there is no getter then there is error while accessing the property using getProperty or EL. for the following declaration, private int var; it is not neccessary that the getter and setter should be public int getVar() public void setVar(int) I can use public int getVars() public void setVars(int) But in this case the property name for bean and EL purpose is vars not var, but the method logic can do anything and can return anything (of given type). It is not neccessary to define the variable int var at all. thanks
|
 |
 |
|
|
subject: Bean property must has both getter / setter ?
|
|
|