Skip to content

Commit ba4593e

Browse files
committed
[QUESTION] wildcards
1 parent 5cf9bad commit ba4593e

4 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎QUESTIONS.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,3 +872,13 @@
872872
}
873873
```
874874

875+
47. how to write ?
876+
877+
```java
878+
// works
879+
public class NumberList<E extends Number> extends ArrayList<E>
880+
881+
// does not work. how to write this
882+
class UntilNumberList<? extends Number> extends ArrayList<?>
883+
```
884+

‎src/main/Foo.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package main;
2+
3+
public interface Foo {
4+
public void process();
5+
}

‎src/main/Main.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Arrays;
5+
import java.util.List;
56

67
public class Main {
78

@@ -81,6 +82,22 @@ public static void main(String[] args) {
8182
System.out.println("number list: " + rawNumberList);
8283
}
8384

85+
class PersonFoo extends Person implements Foo {
86+
public PersonFoo(String name) {
87+
super(name);
88+
}
89+
90+
@Override
91+
public void process() {
92+
93+
}
94+
}
95+
96+
public static void process(List<? extends Foo> list) {
97+
for (Foo elem : list) {
98+
}
99+
}
100+
84101
public static <T extends Comparable<T>> int countGreaterThan(T[] anArray, T x) {
85102
int count = 0;
86103

‎src/main/NumberList.java‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ public Stream<E> parallelStream() {
1515
public Stream<E> stream() {
1616
return null;
1717
}
18-
}
18+
}
19+
20+
// how to write this
21+
// class UntilNumberList<? extends Number> extends ArrayList<?>

0 commit comments

Comments
 (0)