Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Blocker
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-5
-
Fix Version/s: 1.0-RC-1
-
Component/s: None
-
Labels:None
-
Environment:Mustang b82
-
Number of attachments :
Description
Caught: java.lang.ClassCastException: java.lang.Long cannot be cast to java.math.BigDecimal
at Whole.<init>(testScript.groovy:37)
at testScript.run(testScript.groovy:41)
at testScript.main(testScript.groovy)
Java Result: 1
----------------------------------------------------------------
import java.math.BigInteger
import java.math.BigDecimal
class Rational {
final BigInteger numerator
final BigInteger denominator
Rational(BigInteger numerator, BigInteger denominator) {
def gcd = numerator.gcd(denominator)
if (gcd > 0G)
this.numerator = numerator
this.denominator = denominator
}
Rational(BigDecimal number)
{ this(number.unscaledValue(), BigInteger.TEN.pow(number.scale())) }Rational(double number)
{ this(BigDecimal.valueOf(number)) }Rational(BigInteger number)
{ this(number, 1G) }}
class Whole extends Rational {
Whole(BigInteger number)
Whole(long number) { super(number) }
}
x = new Whole(100)
again a problem with super/this. The algorithm for choosing the correct constructor is not correct