Created
October 30, 2023 12:12
-
-
Save MaksimDmitriev/d8bfd7a0633dc20dadcd1654b44f9988 to your computer and use it in GitHub Desktop.
Lower bounded wildcard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ru.maksim.sample; | |
import org.junit.jupiter.api.Test; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class SampleJavaTest { | |
@Test | |
void foo() { | |
addNumbers(new ArrayList<>()); | |
addNumbers(new ArrayList<Number>()); | |
addNumbers(new ArrayList<Object>()); | |
} | |
public static void addNumbers(List<? super Integer> list) { | |
for (int i = 1; i <= 10; i++) { | |
list.add(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment