Say we have a class like this:
class Bar {
boolean b;
}
class Foo {
String zoo;
Bar bar;
}
and then we have a class that extends Foo:
class Stew extends Foo {
public Stew(Bar b, String z){
this.bar = b;
this.zoo = z;
}
}
my question is - is there any way to prevent Stew
from having any non-method fields that aren't in Foo
? In other words, I don't want Stew
to have any fields, I just want Stew
to implement a constructor and maybe a method or two.
Perhaps there is an annotation I can use, that can do this?
Something like:
@OnlyAddsMethods
class Stew extends Foo {
public Stew(Bar b, String z){
this.bar = b;
this.zoo = z;
}
}
purpose - I am going to serialize Stew
to JSON, but I don't want Stew to have any new fields. I want to let any developer working on this file to know that any additional fields will be ignored (or won't be recognized) etc.