unbounded-wildcard Questions
5
Solved
I am mainly a C# developer and I was teaching Data Structures to my friend and they use Java in their University and I saw such an expression in Java:
void printCollection(Collection<?> c) {...
Isallobar asked 27/5, 2012 at 22:22
1
Solved
the below method compiles without problems:
static Stream<Optional<? extends Number>> getNumbers(Stream<Number> numbers) {
return numbers.map(Optional::of);
}
yet if I add a sim...
Leadwort asked 21/12, 2021 at 9:55
3
Solved
Based on the information provided in the link, it says that:
It's important to note that List<Object> and List<?> are not the same. You can insert an Object, or any subtype of Object...
Cordwain asked 30/3, 2015 at 9:0
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 was reading about generics and I did not understand the need for unbound wildcards and how it differs from raw type. I read this question but still did not get it clearly. In the Java tutorial pa...
Beka asked 9/1, 2013 at 16:48
1
I have a getter returning a List with a wildcard:
import java.util.List;
public interface Foo {
List<? extends Bar> getList();
}
Where Bar is an other interface.
When I write an asserti...
Rift asked 15/11, 2017 at 21:18
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
4
Solved
I believe that the type ? in generics is a specific unknown type. Which means, declaring let's say a list of that type would prevent us from adding any type of object into it.
List<?> unknow...
Whiney asked 18/8, 2016 at 9:27
1
Solved
I was playing around in the Scala REPL when I got error: unbound wildcard type. I tried to declare this (useless) function:
def ignoreParam(n: _) = println("Ignored")
Why am I getting this error...
Sharecropper asked 17/7, 2015 at 8:36
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
2
Solved
I did not get this code to compile either way:
List<List> a = new ArrayList();
List<List<?>> b = new ArrayList();
a = b; // incompatible types
b = a; // incompatible types...
Pneumato asked 14/3, 2015 at 23:31
3
Solved
A raw list converts to List<?> just fine. Why can't a list of raw lists convert to a list of List<?>?
{ // works
List raw = null;
List<?> wild = raw;
}
{ // Type mismatch: cann...
Plane asked 5/11, 2014 at 20:41
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
3
Solved
I was reading this article, , about subclassing a builder class. I understood the article but there was one small bit that bothered me. There was this method,
public static Builder<?> builde...
Fuel asked 20/3, 2014 at 6:28
1
Solved
Following on from this question, which provides a solution but doesn't explain it (unfortunately, the links in the answers are now dead):
Take the following method:
void method(Map<?, ?&...
Sportswoman asked 1/11, 2013 at 13:8
1
© 2022 - 2024 — McMap. All rights reserved.