bounded-wildcard Questions
17
Solved
I came across PECS (short for Producer extends and Consumer super) while reading up on generics.
Can someone explain to me how to use PECS to resolve confusion between extends and super?
Encrinite asked 27/4, 2010 at 17:16
6
Solved
Consider this code:
public class DummyClass {
public List<? extends Number> dummyMethod() {
return new ArrayList<Integer>();
}
}
public class DummyClassTest {
public void testMoc...
Triboelectricity asked 9/9, 2011 at 18:59
7
Solved
I have a couple of questions about generic wildcards in Java:
What is the difference between List<? extends T> and List<? super T>?
What is a bounded wildcard and what is an unbounded...
Arcuation asked 30/10, 2008 at 22:57
3
Solved
The Collections.fill method has the following header:
public static <T> void fill(List<? super T> list, T obj)
Why is the wildcard necessary? The following header seems to work just as...
Coppins asked 6/1, 2022 at 0:30
11
Solved
What does List<?> mean, does it mean simply a list of objects of unspecified type?
Googling for the string <?> returns nothing useful (:
Allistir asked 4/12, 2009 at 4:2
1
Solved
I have a class:
class Generic<T> {
List<List<T>> getList() {
return null;
}
}
When I declare a Generic with wildcard and call getList method, the following assignment is illeg...
Serialize asked 28/9, 2020 at 6:32
4
Solved
Most questions about wildcards want to know why something sensible is rejected by the compiler. My question is the opposite. Why is the following program accepted by the compiler?
void test(List<...
Pyre asked 17/9, 2020 at 23:27
2
Solved
Java requires the instantiation of a bounded type parameter to its upper bound class to have a cast, for example:
<T extends Integer> void passVal (T t) {
Integer number = 5;
t = (T) numbe...
Minor asked 27/9, 2019 at 1:15
2
Solved
I have a class with a type parameter.
class MyObject<IdType> {
@Setter
@Getter
private IdType id;
}
And I thought I can add some method for conveniency so I did.
<T extends MyObjec...
Expedition asked 26/6, 2019 at 7:14
3
List<? super IOException> means the list can contain IOException objects or any object that is super class of IOException. Then why the below Line 2 does not compile?
Also in Line 3 FileNot...
Skulk asked 8/5, 2019 at 16:44
3
Solved
Consider this case:
class A {}
class B<T extends A, E extends T> {
B<?, A> b;
B<?, ? extends A> b2;
}
As I understand type bounds, in this case effective upper bounds of bot...
Hardin asked 28/12, 2018 at 13:37
5
Solved
I know that there was a similar question already posted, although I think mine is somewhat different...
Suppose you have two methods:
// Bounded type parameter
private static <T extends Number...
Noncooperation asked 14/8, 2016 at 17:44
5
Solved
Recently, I read this article:
http://download.oracle.com/javase/tutorial/extra/generics/wildcards.html
My question is, instead of creating a method like this:
public void drawAll(List<? exten...
Canvasback asked 15/8, 2010 at 8:19
2
Solved
For the comparing source code in Comparator class
public static <T, U extends Comparable<? super U>> Comparator<T> comparing(
Function<? super T, ? extends U> keyExtractor...
Saltish asked 6/3, 2018 at 6:6
2
Solved
I was following a tutorial about generics in Java defining this static method:
public static <T extends Comparable<T>> T min(T a) { ... }
and saying that
min(new GregorianCalendar()...
Frere asked 10/2, 2018 at 1:15
2
(To clear up the question, 'T' refers to a type parameter declared in Class)
Just as an example, please review the following application:
public class TestClass {
interface InterfaceA{}
inter...
Flatfoot asked 18/11, 2011 at 22:48
5
Solved
I know there's all sorts of counter-intuitive properties of Java's generic types. Here's one in particular that I don't understand, and which I'm hoping someone can explain to me. When specifying a...
Sealed asked 10/7, 2011 at 19:0
4
Solved
The Oracle doc about Wildcards in generics says,
The wildcard can be used in a variety of situations: as the type of a
parameter, field, or local variable; sometimes as a return type
(though i...
Devilmaycare asked 23/6, 2016 at 17:51
3
Solved
In case you need to pass an argument of an interface type to a method you could use two impl.
Use a bounded type parameter:
public static <I extends InterfaceObj> void isTrue(boolean expres...
Gallstone asked 12/8, 2016 at 9:7
3
Using generic wildcard types in return parameters in Java is generally discouraged. For example Effective Java, Item 28 states:
Do not use wildcard types as return types. Rather than providing a...
Maccarone asked 6/1, 2016 at 19:42
3
Solved
The following signature is valid and commonly used in Scala:
trait Collection[A] {
def reduceLeft [B >: A] (f: (B, A) => B): B
}
However, since >: is the Scala equivalent of super in J...
Philosophize asked 14/7, 2015 at 23:14
5
Solved
A bit more specific than Stack Overflow question What is an existential type?, what is the difference between Scala's existential types and Java's wildcard, prefereably with some illustrative examp...
Trestlework asked 23/6, 2009 at 7:8
6
Solved
I've been beating my head against this one for awhile and thought that maybe some fresh eyes will see the issue; thanks for your time.
import java.util.*;
class Tbin<T> extends ArrayList<...
Doggerel asked 21/5, 2015 at 21:48
2
Solved
Why is is that the following code does not compile?
interface Iface<T> { }
class Impl<T> implements Iface<T> { }
class TestCase {
static Class<? extends Iface<?>> ...
Liatrice asked 7/5, 2015 at 1:9
3
Solved
I am new to Java. In this document they give this as a use case for using wildcard:
static void printCollection(Collection c) {
Iterator i = c.iterator();
for (int k = 0; k < c.size(); k++) {...
Ousley asked 24/4, 2015 at 20:27
1 Next >
© 2022 - 2024 — McMap. All rights reserved.