[ 
https://issues.apache.org/jira/browse/GROOVY-11410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17856356#comment-17856356
 ] 

Eric Milles commented on GROOVY-11410:
--------------------------------------

There is an implicit conversion to Class. I think it takes the string value of 
the right expression. I never quite understood why the right could be anything 
besides a string. STC does present an opportunity to tighten this up. 

> type mismatch when the expected type is java.lang.Class
> -------------------------------------------------------
>
>                 Key: GROOVY-11410
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11410
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Priority: Minor
>
> I have the following program
> {code:java}
> class Test {
>   public static void main(String [] args) {
>     java.lang.Class<String> lapse = 1;
>   }
> } {code}
> h3. Actual behavior
> The code compiles, but I get the following runtime error:
> {code:java}
>  Caught: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot 
> cast object '1' with class 'java.lang.Integer' to class 'java.lang.Class' due 
> to: java.lang.ClassNotFoundException: 1
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object '1' with class 'java.lang.Integer' to class 'java.lang.Class' due to: 
> java.lang.ClassNotFoundException: 1
>     at Test.main(test.groovy:3){code}
> h3. Expected behavior
> The code should have been rejected
> Tested against master (commit: e6b9133726af9cdea2bc6db7b55523cd88f7190e)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to