RFR: JDK-8277175 : Add a parallel multiply method to BigInteger [v5]
kabutz
duke at openjdk.java.net
Wed Dec 15 14:44:01 UTC 2021
On Tue, 30 Nov 2021 23:18:21 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> kabutz has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Made forkOrInvoke() method protected to avoid strange compiler error
>
> src/java.base/share/classes/java/math/BigInteger.java line 1909:
>
>> 1907: @Override
>> 1908: public BigInteger compute() {
>> 1909: return a.multiply(b, true, super.parallel, super.depth);
>
> Using `super.` is a little unusual, it's not wrong :-) but not really idiomatic in the source code base.
I cannot remember ever using `super.` like this before either :-) I have a static inner class, which in turn has two static inner classes, which are its subclasses. The inner inner classes want to access the fields of their outer static super class. Since the fields are private, we need to use `super` otherwise we get this compiler error:
error: non-static variable parallel cannot be referenced from a static context
return a.multiply(b, true, parallel, depth);
And if we move the inner inner class up one level, then we also get an error:
error: parallel has private access in RecursiveOp
return a.multiply(b, true, parallel, super.depth);
A solution of course is to make the fields non-private. Then the compiler is happy and we can get rid of the `super`. Since the classes are private anyway, making the fields private does not increase the encapsulation. I will do that to get rid of the `super` FWIW.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6409
More information about the core-libs-dev
mailing list