What is a good way to allow only one non null field in an object : <p>I want to write a class with more than 1 fields of different types but at any time, there is one and only one field of an instance object having non null value.</p>

<p>What I did so far does not look really clean.</p>

<pre class="lang-java prettyprint-override"><code>class ExclusiveField {

    private BigInteger numericParam;
    private String stringParam;
    private LocalDateTime dateParam;

    public void setNumericParam(BigInteger numericParam) {
        unsetAll();
        this.numericParam = Objects.requireNonNull(numericParam);
    }

    public void setStringParam(String stringParam) {
        unsetAll();
        this.stringParam = Objects.requireNonNull(stringParam);
    }

    public void setDateParam(LocalDateTime dateParam) {
        unsetAll();
        this.dateParam = Objects.requireNonNull(dateParam);
    }

    private void unsetAll() {
        this.numericParam = null;
        this.stringParam = null;
        this.dateParam = null;
    }
}
</code></pre>

<p>Does Java support this pattern somehow or is there a more decent way to do it?</p>
