vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

no instance(s) of type variable(s) A exist so that Object conforms to A[]

Open zsrv opened this issue 1 year ago • 0 comments

Version: Quiltflower 1.10.0 (commit d43976c4523bf67344ee61366e997ac43f1927ef)

Original code:

import java.lang.reflect.Array;
import java.util.stream.IntStream;

public class Example {
    private static <T> T[] myMethod(Object[] myObjects, Class<T> clazz) {
        return IntStream.range(0, myObjects.length).mapToObj(i -> myObjects[i]).toArray(size -> (T[])Array.newInstance(clazz, size));
    }
}

Quiltflower output:

import java.lang.reflect.Array;
import java.util.stream.IntStream;

public class Example {
   private static <T> T[] myMethod(Object[] myObjects, Class<T> clazz) {
      return (T[])IntStream.range(0, myObjects.length).mapToObj(i -> myObjects[i]).toArray(size -> Array.newInstance(clazz, size));
   }
}

The output results in this error:

no instance(s) of type variable(s) A exist so that Object conforms to A[]

zsrv avatar Apr 25 '23 00:04 zsrv