Collection field in record causes Class Format Error

Brian Goetz brian.goetz at oracle.com
Thu Aug 1 01:32:54 UTC 2019


The issue here is not the Collection but the generics.  The compiler is not erasing the type before it lowers the record into its desugared form.  

> On May 26, 2019, at 7:58 PM, Francois Green <francois.green at gmail.com> wrote:
> 
> public class Main {
> 
>    public static void main(String[] args) {
>        var item = new Item(List.of());
>    }
> }
> 
> record Item(List<String> strings);
> 
> 
> Exception in thread "main" java.lang.ClassFormatError: Field "strings" in
> class Item has illegal signature "Ljava/util/List<Ljava/lang/String;>;"
>        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
>        at
> java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
>        at
> jdk.compiler/com.sun.tools.javac.launcher.Main$MemoryClassLoader.findClass(Main.java:657)
>        at
> jdk.compiler/com.sun.tools.javac.launcher.Main$MemoryClassLoader.loadClass(Main.java:594)
>        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
>        at Main.main(CFE.java:6)



More information about the amber-dev mailing list