0

I want to have a numeric data type starting at 1. Not use negative and 0.

So I could use Example class

public class Example extends Long {

    private int min = 1;

    public LifeTime(long value) {
        this.value = value;
    }

How could I change the min value of Long class with 1 at this Example data type class?

Is it possible to modify Long by extending the class?

HoRn
  • 1,458
  • 5
  • 20
  • 25

1 Answers1

2

You could just use the constructor as a way to add the validation. E.g.:

public class LifeTime {

private static final int MINIMAL_VALUE = 1;
private long value;

public LifeTime(long value) {
    if (value < MINIMAL_VALUE) {
        this.value = MINIMAL_VALUE;
    } else {
        this.value = value;
    }
}
Patrick Santana
  • 397
  • 3
  • 17