Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2749
| From | isuy <isuy@socal.rr.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Java basic question |
| Date | 2013-08-04 00:54 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <ktl0vs$qd9$1@dont-email.me> (permalink) |
| References | <ktk9ml$5sk$1@dont-email.me> <ktkbn6$dao$1@dont-email.me> <77e17aa4-5636-4f6a-b496-c8a3dfac9ade@googlegroups.com> |
Thank you all for prompt responses.
Very much appreciated.
On 08/03/2013 08:46 PM, Lew wrote:
> Eric Sosman wrote:
>> isuy wrote:
>>> Suppose I have:
>>>
>>> class A {
>>> String index = "string";
>>>
>>> String getPage(String str) { return str; }
>>> }
>
> You are asking the method to return its argument, 'str', not the member
> variable 'index' or anything else.
>
>>>
>>> When I call:
>>>
>>> new A().getPage("index") , it returns "index" instead of "string".
>
> Why do you say "instead of"? You clearly ask 'getPage()' to return its
> argument, which in that call evaluates to "index". What else could it do?
>
>>> What Do I need to do to get "string"?
>
> Code the routine to return what you want instead of its method argument.
>
>> There are lots of possibilities, depending on precisely
>> what you're trying to do. Here are a few:
>>
>> class A {
>> String getPage(String ignored) {
>> return "string";
>> }
>> }
>> // ...
>> String result = new A().getPage("zaphod");
>>
>> class A {
>> String index = "string";
>> String getPage() {
>> return index;
>> }
>> }
>> // ...
>> String result = new A().getPage();
>>
>> class A {
>> String index;
>> A(String thing) {
>> index = thing;
>> }
>> String getPage() {
>> return index;
>> }
>> }
>> // ...
>> String result = new A("string").getPage();
>>
>> class A {
>> String index = "string";
>> String getPage(String str) {
>> if ("index".equals(str)) {
>> return index;
>> }
>> throw new IllegalArgumentException(
>> "bad argument: " + str);
>> }
>> }
>> // ...
>> String result = new A().getPage("index");
>> String failure = new A().getPage("zaphod");
>>
>> // No "class A" at all, and
>> String result = "string";
>>
>> So: What are you trying to do?
>
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar | Unroll thread
Java basic question isuy <isuy@socal.rr.com> - 2013-08-03 18:17 -0700
Re: Java basic question Eric Sosman <esosman@comcast-dot-net.invalid> - 2013-08-03 21:51 -0400
Re: Java basic question Lew <lewbloch@gmail.com> - 2013-08-03 20:46 -0700
Re: Java basic question isuy <isuy@socal.rr.com> - 2013-08-04 00:54 -0700
csiph-web