bounded-wildcard Questions

2

Solved

I have a relatively simple looking problem that I am trying to solve. There doesn't seem to be an intuitive way to do this or, I am missing something here. Consider this method to find the main im...
Infidel asked 24/4, 2015 at 22:41

2

Solved

Assume class B inherits from class A. The following is legal Java: List<A> x; List<? super B> y = x; In terms of the specification, this means that List<A> assignsTo List<? ...
Fistic asked 24/4, 2015 at 20:39

2

Solved

The following class defines two methods, both of which intuitively have the same functionality. Each function is called with two lists of type List<? super Integer> and a boolean value which ...
Dawnedawson asked 11/1, 2014 at 17:44

2

Solved

The following statements: URLClassLoader ucl = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class<URLClassLoader> uclc = ucl.getClass(); fail with error: Type mismatch: cannot con...
Mixedup asked 9/6, 2014 at 8:11

2

Solved

Why is it that Java can infer the common ancestor of multiple upper-bounded types, but not of lower-bounded types? More specifically, consider the following examples: static class Test { static...
Barolet asked 26/12, 2014 at 4:34

2

Why is this code valid ArrayList<?>[] arr = new ArrayList<?>[2]; but the following two are not? ArrayList<? extends Object>[] arr = new ArrayList<? extends Object>[2]; A...
Defer asked 1/10, 2014 at 10:54

4

Solved

Simple class: class Pair<K,V> { } And a few assignments: Collection<Pair<String,Long>> c1 = new ArrayList<Pair<String,Long>>(); Collection<Pair<String,Long&...
Lauralauraceous asked 14/7, 2014 at 13:28

2

Solved

(If this is a duplicate please point me to the right answer! I searched and read several (>5) related questions but none seemed on the mark. Also looked at the Generics FAQ and other sources...) I...
Assonance asked 4/7, 2014 at 0:55

2

Solved

The following compiles just fine in JDK8, but gives an incompatible types error with JDK7. List<List<? extends Number>> xs = Arrays.asList(Arrays.asList(0)); According to this answer...
Geneviegenevieve asked 12/6, 2014 at 15:56

4

Solved

I have the following two interfaces: /** * A marker interface to denote that an object implements a view on some other object. * * @param <T> The type of object that is viewed */ public ...
Coenosarc asked 29/4, 2014 at 12:16

2

Solved

How come one must use the generic type Map<?, ? extends List<?>> instead of a simpler Map<?, List<?>> for the following test() method? public static voi...
Consolidate asked 2/4, 2014 at 8:54

2

Suppose I have a method "mix" that takes two Lists of possibly different types T and S and returns a single List containing the elements of both. For type-safety, I'd like to specify that the retur...
Jadejaded asked 18/8, 2013 at 21:12

4

I wonder why does this piece of code compile successfully? Source code: abstract class A<K extends Number> { public abstract <M> A<? super M> useMe(A<? super M> k); } C...
Pantile asked 23/12, 2013 at 23:32

4

Solved

So I am reading about generic method and I am get confused. Let me state the problem here first: In this example: Suppose that I need a version of selectionSort that works for any type T, by using...
Dover asked 10/12, 2013 at 15:3

1

Solved

When I try to compile the following code: LinkedList<List<? extends Number>> numList = new LinkedList<List<Integer>>(); I get an incompatible type error: Required: Linke...
Exorbitant asked 25/11, 2013 at 22:40

2

Solved

I want to have a Class object, but I want to force whatever class it represents to extend class A and implement interface B. I can do: Class<? extends ClassA> Or: Class<? extends Inte...
Multiple asked 13/4, 2009 at 23:21

1

I am wondering what is wrong with this code: Map <? extends String, ? extends Integer> m = null; Set<Map.Entry<? extends String, ? extends Integer>> s = m.entrySet(); The compi...
Fairminded asked 20/9, 2013 at 0:51

2

Solved

Suppose I have this in Java: List<String> list = new ArrayList<String>(); list.getClass(); The type of the last expression is Class<? extends List>. I understand why, due to er...

3

Solved

I am trying to read and understand some Java code. Here it is: protected LoadTarget<? super PopulationLoadContext> createTarget(PopulationLoadContext context) { return createTransacti...
Amazon asked 24/7, 2013 at 22:30

2

Solved

Why do the utility factory methods often use a specific generic parameter (like T) instead of a bounded wildcard parameter (like ? super T)? For instance, the signature of Functions#forPredicate i...
Calendre asked 31/1, 2013 at 17:11

6

Solved

Is there ever a difference between an unbounded wildcard e.g. <?> and a bounded wildcard whose bound is Object, e.g. <? extends Object>? I recall reading somewhere that there was a dif...
Book asked 6/1, 2010 at 20:33

3

I'm having trouble understanding why I can use bounded wildcards like this, if I can't (seem to) make any (genericly-typed) use of it. If I have a wildcard field in a class, I can't use any of the...
Jovanjove asked 12/1, 2013 at 15:55

2

Solved

I'm stuck trying to translate some Java code that uses (bounded) wildcard generics to C#. My problem is, Java seems to allow a generic type to be both covariant and contravariant when used with a w...
Arenaceous asked 12/1, 2013 at 2:16

1

Solved

I'm stuck trying to translate some Java code that uses (bounded) wildcard generics to C#. My problem is, Java seems to allow a generic type to be both covariant and contravariant when used with a ...
Caryloncaryn asked 11/1, 2013 at 11:40

1

class Aliphatic<F> extends Organic<F>{} class Hexane<G> extends Aliphatic<G>{} public class Organic<E>{ void react(E e){} static void main(String[] args){ Organic&l...
Brigandine asked 15/10, 2012 at 14:54

© 2022 - 2024 — McMap. All rights reserved.