1

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.

Ghasan غسان
  • 5,577
  • 4
  • 33
  • 44
  • Where exactly does it say that generic bounds in java 7 are exclusive? – Bohemian May 25 '13 at 04:35
  • @Bohemian You mean the book? It is mentioned in 'Using Wildcard Arguments' in Generics chapter. This edition discusses SE 6, not 7, so I thought there might be a difference. – Ghasan غسان May 25 '13 at 04:41
  • 3
    Well the book is wrong! Generic bounds are *inclusive* no matter which version of java you are using. Just because some bozo writes something in a book does not make it so. – Bohemian May 25 '13 at 05:27

2 Answers2

2

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);
                }
        }
}
Cameron Skinner
  • 51,692
  • 2
  • 65
  • 86
guido
  • 18,864
  • 6
  • 70
  • 95
1

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.

Apprentice Queue
  • 2,036
  • 13
  • 13