I'm trying to use java class BitSet
as a field for a customized class. And I want the class to use a default BitSet with all bits set.
import java.util.BitSet;
public class MyClass {
private BitSet mask;
public MyClass() {
this(new BitSet(4));
// want to set all bits first
// something like
// this( new BitSet(4).set(0,3) );
}
public MyClass(BitSet mask) {
this.mask = mask;
}
}
By default BitSet
constructor unsets all bits. So before I send it as an anonymous object, I would like call set(int, int)
method to set all bits. I know that I could simply initialize the field mask
to a new BitSet
and then call set(int, int)
method from there.
However, in general I'm wondering is it possible to access an instance method at time of object instantiation?