This is the outer class I need to extend:
public class Binary { public Binary( byte type , byte[] data ){ _type = type; _data = data; } public byte getType(){ return _type; } public byte[] getData(){ return _data; } public int length(){ return _data.length; } final byte _type; final byte[] _data; }
And this is the subclass I created:
import org.bson.types.Binary; public class NoahId extends Binary { public NoahId(byte[] data) {
I want to force all my subclasses (NoahId) to have byte [] data of a certain length or throw an exception if not. How can I perform such checks if the constructor call should be the first statement in the constructor of the subclass?
Using a static method to create my class allows me to do the validation, but I still need to define an explicit constructor.
source share