1

I have enum class which consists of bigint constants.

public enum Constants {
    CONST1(new BigInteger("12783786")),
    CONST2(new BigInteger("489578758"));

    BigInteger id;

    Constants(BigInteger id) {
        this.id = id;
    }

    BigInteger getId() {
        return id;
    }
}

Is there any default method which will be called when enum is passed to a method as an argument. Now for a method like process(BigInteger id) i have to write code like process(CONST1.getId()). I want it to look like process(CONST1). Thanks a lot for answers.

Stepan Pogosyan
  • 562
  • 1
  • 7
  • 15
  • 1
    Change the method signature to `process(Constants constant)`. (This usage illustrates why enums typically have singular names.) – Kevin Krumwiede Sep 21 '15 at 01:06
  • 4
    If you're trying to make constant `BigInteger` values, `public static final BigInteger`s might be a better choice than `enum`s. – resueman Sep 21 '15 at 01:07
  • I cant do that. These methods are provided by third-party library. Also some me process methods are used by other people and they use bigints. I decided to use static fields in a common class but with a private default constructor. Thanks for answers – Stepan Pogosyan Sep 21 '15 at 01:09
  • The duplicate discusses the problem for `String`. It's the same for `BigInteger` and your `getId` method. – Sotirios Delimanolis Sep 21 '15 at 01:15
  • 1
    I would say this is a misuse of `Enum`. You should just declare the various constants you need as static `BigInteger`. – user207421 Sep 21 '15 at 01:27

0 Answers0