|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Get method
Hi,
I am having a simple problem. Whe does my get mthod dosent work in my JSP. eg. in jsp --> <input name='checklist'> in javabean --> public String getChecklist() { return checklist; } But it's empty --> System.out.println(getChecklist()); |
|
#2
|
|||
|
|||
|
I got help from my friend a software engineer.
It was my mistake. In java the first letter of get/set method must be the opposite case eg variable firstname --> getFirstname. and the other letter must be the same. TQ |
|
#3
|
|||
|
|||
|
hmm, to my understanding, that shouldn't matter at all, for instance, I could name the getFirstName() method as aaaaa() method. The problem would be trying to remember the name given to the method.
As an example, take a look at this code: Code:
public class TestGetSetMethod{
String myString; //Creates a new String
public TestGetSetMethod(String temp){
GOOGLEset(temp + " Hotel"); //sets
System.out.println(GOOGLEget()); // gets
}
public void GOOGLEset(String s){
myString = s;
}
public String GOOGLEget(){
return myString;
}
public static void main(String[] args){
TestGetSetMethod t = new TestGetSetMethod("Paradise");
}
}
/*
* Output: Paradise Hotel
*/
I named the get method GOOGLEget() and the set method GOOGLEset(), as you can see is hard to figure out that the get and set methods are related to myString, yet the code still works. Ideally I would have named the get method as getMyString, and the set method as setMyString. However, it's important to note that java is case sensitive, so if you name a method aAaA(), you have to call it by writting exactly aAaA(). I think your problem was because of that. Last edited by daniel_g : March 27th, 2007 at 02:15 AM. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Get method |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|