Question

I have a large non static JAVA function, which uses this reference at several places inside it. I want to convert it to static function and pass "this" reference as a parameter, so that I can take it to utility class.

Is there any tool which can automate this process?

UPDATE: Please share if some one has his own quick way of doing this(without using any tool).

Was it helpful?

Solution

Let the method myMethod reside in the class Foo, and you need to make it static in the class Util.

  1. Declare private Foo foo; in Util.
  2. In Eclipse, use the Move refactoring on myMethod, choose Util as the target.
  3. Add the static modifier to the moved method and fix the accesses to the added Foo foo's internals.
  4. Remove the private Foo foo; from Util.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top