Hi,
how can I add a field, getter and setter to all implementations of MyInterface (in the current project or folder?)
Hi,
how can I add a field, getter and setter to all implementations of MyInterface (in the current project or folder?)
I don't think there's a one-step way to go about this. You could add the getter & setter to the interface, then let the compiler tell you where your implementers are, and it should be a simple copy & paste to place the field, getter, and setter into every class after the first.
Alternatively, you could transform your interface into an abstract class, or introduce an abstract class between your interface and your concrete classes, but that's only if your classes don't already extend other classes.
Source
, then Override/Implement Methods...
.Mission accomplished.
[Edited]
When I wrote these steps, I thought that your intention was to create stubs of newly-introduced interface methods, in all classes that implement that interface.
Now that I am re-reading your request, I'm having a hard time understanding what it is exactly that you want to do. You wrote:
how can I add a field, getter and setter to all implementations of MyInterface
So, you have an interface named MyInterface
and 1,000 classes implementing it.
You would like to introduce a new field, a getter and a setter for that field. So I guess my (and perhaps others') first difficulty is that you can't add a field to an interface, unless it's final
- so your wish to "add a field to an interface" just doesn't sound right.
I suppose it would help if you give us a 30,000ft high-level diagram / explanation about your hierarchy and exactly what it is that you're trying to accomplish.