package Test2016;

import java.util.ArrayList;
import java.util.List;

public class Test2016 {

	public static void main(String[] args) {
		
		List<? super Fruit> first = new ArrayList<Fruit>();	//Fruit -> Apple
		
		first.add(new Apple());
		first.add(new Fruit());
		first.add(new RedApple());
		
//		first.add(new Food());	//error
		
		System.out.println(first.get(0));
		System.out.println(first.get(1));
		
		List<? extends Apple> second = new ArrayList<Apple>();
		
		second.add(null);
	}
	
}


class Food {
}

class Fruit extends Food {
}

class Apple extends Fruit {
}

class RedApple extends Apple {
}

 

相关文章:

  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-11-17
  • 2021-10-16
  • 2021-09-19
猜你喜欢
  • 2022-01-23
  • 2022-12-23
  • 2022-03-05
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2021-05-29
相关资源
相似解决方案