Nested wildcards with lower bounds

心已入冬 提交于 2019-12-06 04:25:57

Example 1:

  1. Is List<Pair<Integer>> a subtype of List<? extends Pair<? extends Number>>?
  2. It would be if Pair<Integer> is a subtype of Pair<? extends Number>. Is it?
  3. Yes, because Integer is a subtype of Number.

Example 2:

  1. Is List<Pair<Number>> a subtype of List<? extends Pair<? super Number>>?
  2. It would be if Pair<Number> is a subtype of Pair<? super Number>. Is it?
  3. Yes, because Number is a supertype of Number.

Example 3:

  1. Is List<Pair<Object>> a subtype of List<? super Pair<? super Number>>?
  2. It would be if Pair<Object> is a supertype of Pair<? super Number>. Is it?
  3. No, it is not. A parameterized type with a specific parameter can never be a supertype of a parameterized type with a wildcard.

Example 4:

  1. Is List<Pair<Integer>> a subtype of List<? super Pair<? extends Number>>?
  2. It would be if Pair<Integer> is a supertype of Pair<? extends Number>. Is it?
  3. No, it is not. A parameterized type with a specific parameter can never be a supertype of a parameterized type with a wildcard.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!