This is a static factory method, which returns an instance of BigInteger
.
public static BigInteger valueOf(long val)
{
if (val == 0)
return ZERO;
if (val > 0 && val <= MAX_CONSTANT)
return posConst[(int) val];
else if (val < 0 && val >= -MAX_CONSTANT)
return negConst[(int) -val];
return new BigInteger(val);
}
See, it's either returning a new BigInteger(val)
or going through BigInteger
array instance members to return an already existing BigInteger
. For reference, here's the static block which creates the arrays:
private static BigInteger posConst[] = new BigInteger[MAX_CONSTANT+1];
private static BigInteger negConst[] = new BigInteger[MAX_CONSTANT+1]
static
{
for (int i = 1; i <= MAX_CONSTANT; i++)
{
int[] magnitude = new int[1];
magnitude[0] = i;
posConst[i] = new BigInteger(magnitude, 1);
negConst[i] = new BigInteger(magnitude, -1);
}
}