[ https://issues.apache.org/jira/browse/GROOVY-7690?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-7690: ----------------------------------- Assignee: Eric Milles > TypeChecked Groovy does not throw illegal assignment error at compile time > when using raw generic type > ------------------------------------------------------------------------------------------------------ > > Key: GROOVY-7690 > URL: https://issues.apache.org/jira/browse/GROOVY-7690 > Project: Groovy > Issue Type: Bug > Affects Versions: 2.4.5 > Reporter: Emanuel Seidinger > Assignee: Eric Milles > Priority: Major > > I want to provoke a compiler error. I am omitting the type parameter of a > generic List and use it as a raw type. When getting an object from the raw > list it should be of type Object. When casting this Object implicitly to an > Integer the compiler should throw an illegal assignment error but it doesn't. > The following code example should illustrate the problem. Case 2 and 3 should > throw the same error but only case 3 is producing an error. > {code} > import groovy.transform.TypeChecked > @TypeChecked > class Test { > static method() { > ArrayList<Integer> integerArrayList = new ArrayList<>(); > ArrayList rawArrayList = new ArrayList(); > ArrayList<Object> objectArrayList = new ArrayList<>(); > integerArrayList << 1; > rawArrayList << new Object(); > objectArrayList << new Object(); > Integer x = integerArrayList.get(0); // Case 1: works as expected > Integer y = rawArrayList.get(0); // Case 2: doesn't throw a > compile error but should > Integer z = objectArrayList.get(0); // Case 3: throws a compile > error as expected > } > } > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)