Implement as field/getter/setter

It's easy to generate getters and setters for given fields. It's also easy to extract the getters into an interface. But how do I do the reverse?

Image you have written all these interfaces with String getName(); and so on. How to generate implementation classes that implement these interfaces through fields "name" and a getters/setters? I can't seem to find a helper that would complete this boilerplate for me. I can say "implement interface/methods" and I get a method body that throws UnsupportedOperation. It would be great if I could tag interface methods with a hint "implement as getter of a field - create/reuse field".

The thing that comes closest is to type "return ]]>;" as implementation and have IDEA create the field. For 20 getters that's still annoyingly much.

Is there a way I overlooked how to achieve this?


Comment actions Permalink

I don't know of any way to do it when you start from the interface. Most IntelliJ users would simply create the implementation class with the requisite fields, have IntelliJ create the getters/setters, and then do an Extract Interface refactoring to copy those into an interface.

Comment actions Permalink

Thanks. Looks like a potential feature request ...


Please sign in to leave a comment.