The following codes are based on Java.
Here, the famous method "toUpperCase()", can be invoked like this:
String s = new String("abc");
String ss = s.toUpperCase();
//result: ss = "ABC"
For this: s.toUpperCase()
We didn't pass a value to the method, so this method cannot has a meaningful return value.
To explain what is called a not-meaningful return value, here is an example:
//not pass a value to the method
String toUpperCase(){
...
return ???;
}
As above, the return value has no relationship with that object called "s". (the invoking of a non-parameter method is often independent from the objects). If I invoke this non-parameter method: String ss = s.toUpperCase();
how can that return a value that has any relationship with the object "s"
And the following is called meaningful:
//pass a value to the method
static String toUpperCase(String str){
.... //to change the "str" into uppercase
return str;
}
Now I can invoke the method toUpperCase() like this:String ss = String. toUpperCase(s);
Since I pass the "s" (its address) to the method, I can do anything I wish to change the object and return a meaningful return value.
Based on the above, I have a reasonable doubt about this method
s.toUpperCase()
. since it cannot return a meaningful return value.