Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #27481

Re: Unable to Overload toString for Object

From leif.roar@invalid.com (Leif Roar Moldskred)
Subject Re: Unable to Overload toString for Object
Newsgroups comp.lang.java.programmer
References <705891c8-b170-44c0-866f-48eec7b38c4d@googlegroups.com>
Organization Dimnakorr
Message-ID <a4GdnaxRH4JrfGTPnZ2dnUVZ8vednZ2d@giganews.com> (permalink)
Date 2014-02-11 02:40 -0600

Show all headers | View raw


Ojesh Dugar <ojesh.u@gmail.com> wrote:
> 
> Its not returnig OJEABX as expected. Instead bugs=[Ljava.lang.Object;@2ee5e48a being diplayed.
> Where am i going wrong.??

The /toString()/ you implement in your /Search/ class will only have an effect for objects
that are instances of this particular class. The result returned by the call to
/rpcClient.execute()/ is not a /Search/ instance.

Java isn't a prototype-based language. You can't modify or add methods to an existing object;
you can only define a new class that overrides methods in the original class and then ensure
that when you instantiate the relevant objects that you instantiate them from the new class
and not the old. When you're not in control of the object instantiation (for instance, 
when the objects are created in a third party library) you will have to solve the problem
in some other way. 
 
-- 
Leif Roar Moldskred

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-10 22:59 -0800
  Re: Unable to Overload toString for Object leif.roar@invalid.com (Leif Roar Moldskred) - 2014-02-11 02:40 -0600
    Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-11 01:03 -0800
      Re: Unable to Overload toString for Object Lew <lewbloch@gmail.com> - 2014-02-11 15:49 -0800
        Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-12 00:38 -0800
          Re: Unable to Overload toString for Object markspace <markspace@nospam.nospam> - 2014-02-12 10:37 -0800
            Re: Unable to Overload toString for Object Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-02-12 13:57 -0500
              Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-12 20:24 -0800
                Re: Unable to Overload toString for Object Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-02-13 08:29 -0500
            Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-12 20:58 -0800
              Re: Unable to Overload toString for Object markspace <markspace@nospam.nospam> - 2014-02-12 21:29 -0800
                Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-13 00:59 -0800
  Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-11 01:06 -0800
    Re: Unable to Overload toString for Object Ojesh Dugar <ojesh.u@gmail.com> - 2014-02-11 01:27 -0800

csiph-web