[ 
https://issues.apache.org/jira/browse/GROOVY-7696?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King closed GROOVY-7696.
-----------------------------

> Bug with @TypeChecked and generic properties of Java classes used in binary 
> expressions
> ---------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7696
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7696
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 2.4.5
>            Reporter: Marc Ewert
>            Assignee: Paul King
>             Fix For: 2.4.6
>
>
> I have the following two Java Classes:
> {code}
> 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;
>     }
> }
> {code}
> {code}
> 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));
>     }
> }
> {code}
> And a Groovy test class with @TypeChecked annotation:
> {code}
> 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)
>     }
> }
> {code}
> Compiling the class leads to the error message:
> {code}
> 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.
> {code}
> Removing the @TypeChecked annotation or moving the Java classes into the 
> Groovy class as static inner classes suppresses the compilation error.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to