Main Class package Comparator.Bean; import java.math.BigDecimal; import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; /** * ? extends E : 接收E或者是E的子类对象.上限 * ? super E :接收E或者E的父类对象.下限 * @author asus
v 一.程序中无形之中用到的泛型 import java.util.*; class Person implements Comparable<Person>{ String name; int age; Person(){ name = ""; age = 0; } Person(String name, int age){ this.name = name; this.age = age; } public String toString(){ return name
1 协变数组类型(covariant array type) 数组的协变性: if A IS-A B then A[] IS-A B[] 也就是说,java中的数组兼容,一个类型的数组兼容他的子类类型数组. 协变数组好处:使得代码的灵活性更强. 协变数组的坏处:过于灵活导致类型混乱,比如: Peron[] arr = new Employee[5]; //Employee IS-A Person 可以执行 arr[0] = new Student();// Student IS-A Person
Java总结篇系列:Java泛型 转自:http://www.cnblogs.com/lwbqqyumidi/p/3837629.html 一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(String[] args) { 4 List list = new ArrayList(); 5 list.add("qqyumidi"); 6 list
为什么需要泛型? public class GenericTest { public static void main(String[] args) { List list = new ArrayList(); list.add("qqyumidi"); list.add("corn"); list.add(100); for (int i = 0; i < list.size(); i++) { String name = (String) list.get
一. 泛型概念的提出(为什么需要泛型)? 首先,我们看下下面这段简短的代码: 1 public class GenericTest { 2 3 public static void main(String[] args) { 4 List list = new ArrayList(); 5 list.add("qqyumidi"); 6 list.add("corn"); 7 list.add(100); 8 9 for (int i = 0; i < lis