문제

I am reading Java the Complete Reference 7th edition, and it says that lower bound in Java Generics are exclusive, but I found the opposite here (It says that it is inclusive.) Is it because SE 6 differs from SE 7?

Edit: Java the Complete Reference 7th edition discussed SE 6.

도움이 되었습니까?

해결책 2

In the specification, they use the word "subtype" in parametrization to mean inclusive subtype. In section 4.10, it defines the phrase "proper subtype/proper supertype" to mean exclusive subtype/supertype while "subtype/supertype" means inclusive subtype/supertype.

다른 팁

The bound is inclusive.

It is very easy to try it by yourself:

import java.util.*;
import java.lang.*;

class Main {
        public static void main (String[] args) throws java.lang.Exception {
                addNumbers(new ArrayList<Integer>());   
        }
        public static void addNumbers(List<? super Integer> list) {
                for (int i = 1; i <= 10; i++) {
                        list.add(i);
                }
        }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top