Implement Interface > automatically create fields/getters/setters

i created inteface
interface Foo {
int getId();
void setName(String name);
}

i type "alt+enter" on interface name and click "implement inrterface" command
then i've got

public class FooImpl implements Foo {
public int getId() {
return 0;
}
public void setName(String name) {
}
}

and now i don't know how to convert al this methods to private fields with getters and setters

it would be great to have option in "Implement Inteface" dialog:
"try to reproduce fields for getters and setters"
with this option checked i'd get

public class FooImpl implements Foo {
private int id;
private String name;

public int getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
}

5 comments

Hm, might be useful. You can always request a feature in Jira: http://www.jetbrains.net/jira/

Usually I do it the other way round:
Create a class with just the fields.
Code -> Generate -> getters and setters
Refactor -> Extract interface

1


I think it's quite rare to have an interface full of 'bean methods'.
As you mentioned, the sequence [create fields->create getter/setter->extract
interface] is probably is fastest.

When the interface already exists, I would try:
1) Implement interface
2) Visit all setters, invoke 'create field' intention
3) Visit all getters, place caret at return expression, smart complete for
field


0

i would try the same 3 things
but often i have only getters (all setterings in constructor)

0

Usually I do it the other way round


this is good for one implementing class
what if i want many implementations?
what if i already have interface from another programmer?

0

M> this is good for one implementing class
M> what if i want many implementations?
M> what if i already have interface from another programmer?

1. Make a first "model" implementation.
2. Copy this implementation the number of times you need.


0

Please sign in to leave a comment.