import java.util.*;
public class SimpleArrays
{
@SafeVarargs
public static <T> List<T> asList( T... a )
{
return new ArrayList<>( a );
}
}
asList()
is taken from Oracles JDK implementation of java.util.Arrays.
The error is
error: cannot infer type arguments for ArrayList<>
return new ArrayList<>( a );
1 error
How can this work? Oracle uses the same compiler that we do.
Attention: The ArrayList
used in the java.util.Arrays
class is not java.util.ArrayList
, but a nested class java.util.Arrays.ArrayList
.
In particular, this class has an constructor which takes a T[]
as argument, which java.util.ArrayList
does not have.
Copy this class, too, and it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With