Description
I have the following two Java Classes:
import java.math.BigDecimal; public abstract class Attribute<T> { private BigDecimal numericValue; public abstract T getValue(); public abstract void setValue(T value); public BigDecimal getNumericValue() { return numericValue; } public void setNumericValue(BigDecimal numericValue) { this.numericValue = numericValue; } }
import java.math.BigDecimal; public class LongAttribute extends Attribute<Long> { public Long getValue() { return getNumericValue() == null ? null : getNumericValue().longValue(); } public void setValue(Long value) { setNumericValue(BigDecimal.valueOf(value)); } }
And a Groovy test class with @TypeChecked annotation:
import groovy.transform.TypeChecked @TypeChecked class Scratch { public static void main(String[] args) { LongAttribute attr = new LongAttribute(); attr.value = 0L println "getter: " + attr.value println "smaller as 0? " + (attr.value < 0) } }
Compiling the class leads to the error message:
Error:(10, 36) Groovyc: [Static type checking] - Cannot find matching method java.lang.Object#compareTo(int). Please check if the declared type is right and if the method exists.
Removing the @TypeChecked annotation or moving the Java classes into the Groovy class as static inner classes suppresses the compilation error.