fixing a mistaken toString() method

M

Mohun Biswas

Here's a small problem that's bugging me. I wrote a class for which I
originally provided a toString() method that, foolishly, did the wrong
thing. Now, as part of a refactoring exercise I want to fix it and find
and fix all the places the bad variant was used. I can't search
textually for "toString" because of the magic associated with that name,
such that it's invoked automatically when an instance is used in a
String context. I considered changing the method signature and letting
the compiler tell me where things go blooey, but of course the compiler
will simply find super.toString(), all the way back to Object if need
be. I'm thinking of creating a custom Exception and declaring my
toString to throw it so the compiler can tell me where it isn't caught
but that's ugly.

Is there a clean, deterministic way of solving this little corner case?

Thanks,
MB
 
R

rkm

You didn't mention what IDE you're using, if any. In
Eclipse, you would right click (ctrl-click on mac) on your
toString method, and select
refactor->search->references->workspace, or something close
to that. It would find references to just your
implementation, not the inherited ones.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top