java: static methods and inheritance. Is there a way around this? -
i have following problem:
there's engine invokes static method of superclass (which call superclass.staticmethod). have no access code of engine can reflect on it.
i subclassed superclass (generating subclass) , able edit private fields inherited superclass through reflection. ok point.
the engine has class (let's call constants) has static final instances of lot of classes, including superclass, not subclass, since it's not part of engine.
now, superclass.staticmethod equivalent of this:
public int staticmethod(int i) { if(i == 0) return constants.superclassinstance.field_1; else if(i == 1) return constants.superclassinstance.field_2; }
both superclass.field_1 , superclass.field_2 private (and not static, people thinking were, i'm editing question bit), static method has visibility of them because it's member of superclass. said, able set values of fields on inherited subclass through reflection, because of way supperclass.staticmethod works, shown above, has no effect on it.
i don't think can change superclassinstance.field_1 , field_2, or break way superclass works, slightly, sensibly.
is there way solve this?
this seems me xy problem. of issues design.
for one, purpose of having private static final? since final, might public. have seen regularly, think is, generally, bad practice.
making static, makes global. in case of things singleton, there desire hide globalness, of static variable. however, there typically helper functions reveal useful functionality of "hidden, global".
it sounds parent class lacks methods make parent class useful. there way can change design of parent class, rather utilize these hacks make project work?
Comments
Post a Comment