modeller modeller - 3 months ago 9
Java Question

In intelliJ, how to move an method to an implementing class of an interface?

I am using intelliJ 2016.2.1.

I have a method

foo()
in main class Test:

class Test {
IService iService;

foo(){...}

}


IService
is an interface, it has one implementing class
ServiceImpl
.
When I put caret on
foo
, and select move, intelliJ only allows me to select
IService
. But I actually want
ServiceImpl
as move destination.

And if I continue the move, intelliJ will put the method implementation inside the interface
IService
. But I want to have an declaration there.




Question: How do I refactor foo(), to move its method implementation into ServiceImpl, and method declaration in IService?

Answer

After you move the method to IService, use Refactor | Push Members Down... to move it to ServiceImpl.