import com.google.common.collect.UnmodifiableIterator;
import javax.naming.NamingException;import javax.naming.directory.Attribute;import javax.naming.directory.BasicAttribute;import java.util.ArrayList;
import static com.google.common.collect.Iterators.forEnumeration;import static com.google.common.collect.Lists.newArrayList;
public class NewArrayListIssue { public static void main(String[] args) throws NamingException {
UnmodifiableIterator<?> elements = forEnumeration(getEnumeration().getAll()); System.out.println("declarefirst = " + newArrayList(elements)); // calls newArrayList(Iterator<? extends E> elements)
ArrayList directCopy = newArrayList(forEnumeration(getEnumeration().getAll())); System.out.println("useDirectly = " + directCopy); //calls newArrayList(E... elements) }
public static Attribute getEnumeration(){ return new BasicAttribute("foo",1); }}
--
guava-...@googlegroups.com
Project site: https://github.com/google/guava
This group: http://groups.google.com/group/guava-discuss
This list is for general discussion.
To report an issue: https://github.com/google/guava/issues/new
To get help: http://stackoverflow.com/questions/ask?tags=guava
---
You received this message because you are subscribed to the Google Groups "guava-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to guava-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/guava-discuss/c577bfa1-fd9a-43f4-8a79-97f407ef7baf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Am 22.01.2015 um 02:16 schrieb Tim Peierls:
Did you mean to have raw ArrayList?
If so: All bets are off when you use raw types. I get a compiler warning
about unchecked array creation.
It's not really "all bets are off", in fact the rule about that kind of situation are quite explicit.
The situation is that the compiler cannot check that this combination is always typesafe, and manual checking is awkward and beyond the abilities of most Java programmers.
I wouldn't expect a compiler error with that one, it's the same compiler
after all; this sounds like an intentional change.
Though that's weird. Did they change the ambiguity resolution between 7
an 8?
Or maybe my analysis is totally off the mark.