I have class like this:
abstract class Parent {
protected Parent(Raw rawData) {
deserialize(rawData);
}
protected abstract void deserialize(Raw rawData);
}
class Child extends Parent {
final byte firstByte;
public Child(Raw rawdData) { super(rawData); }
protected void deserialize(Raw rawData()) {
firstByte = rawData.getFirst();
}
}
So basically any child class that extends Parent will define a deserialize() to deserialize the rawData to fill in their member variables, and in their constructor they will just do super(rawData). The deserialize function of the child class will automatically execute.
However doing this Java does not allow me to define member variables as final which is weird because I'm doing initialization in the constructor. What is the best way to do the same functionality but allowing member to be final ?
Aucun commentaire:
Enregistrer un commentaire