Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Understanding wildcards in Java generics
- List<String> a = new ArrayList<String>();
- a.add("foo");
- // b is a List of anything
- List<?> b = a;
- // retrieve the first element
- Object c = b.get(0);
- // This is legal, because we can guarantee
- // that the return type "?" is a subtype of Object
- // Add an Integer to b.
- b.add(new Integer (1));
- Object c = b.get(0);
- public Foo findAFooThatILike(Collection<? extends Foo> foos);
- public Foo findAFooThatILike(Collection<Foo> foos);
Add Comment
Please, Sign In to add comment