3 ms·
"this() must always be called first in the constructor" is not true! Consider the following example: Foo(long x) { ... } Foo(double y) { this(Math
by nayuki 4y ago
"this() must always be called first in the constructor" is not true! Consider the following example:
Foo(long x) { ... }
Foo(double y) { this(Math.round(y)); }
In the second constructor, the first call is Math.round(), followed by Foo(int). I am talking about evaluation order, not lexical order.
I found myself needing to work around the limitation recently: https://github.com/nayuki/PNG-library/blob/b92cedc23b1fc32d51bbc528797b9b55eba6bc17/src/io/nayuki/png/chunk/Gama.java#L36-L49 https://github.com/nayuki/PNG-library/blob/b92cedc23b1fc32d5...