JDK1.5开始实现了对泛型的支持,但是java对泛型支持的底层实现采用的是类型擦除的方式,这是一种伪泛型.这种实现方式虽然可用但有其缺陷. <Thinking in Java>的作者 Bruce Eckel也曾撰文<这不是泛型>批评过JDK1.5中的泛型实现. 看了部分Java编程思想中泛型一章的内容,现在很晕,越看越觉得晕,这篇文章先欠着吧,等我再看一遍深入理解Java虚拟机JVM高级特性与最佳实践之后,或许能理解泛型的实现细节,那个时候再完成这篇文章. 感兴趣的朋友可以看看下…
一.栗子 public class GenericityInher { //error: Type mismatch: cannot convert from ArrayList<Child> to ArrayList<Parent> public ArrayList<Parent> list(){ return new ArrayList<Child>(); } //right public Parent inher(){ return new Child…
一.栗子 public class GenericityInher { //error: Type mismatch: cannot convert from ArrayList<Child> to ArrayList<Parent> public ArrayList<Parent> list(){ return new ArrayList<Child>(); } //right public Parent inher(){ return new Child…
class Fruit{} class Apple extends Fruit{} class SubApple extends Apple{} class Orange extends Fruit{} class Holder<T>{ private T value; public Holder(){} public Holder(T value){this.value = value;} public T getValue() { return value; } public void s…
using System; using System.Data.Common; using System.Data.Entity.Core.Objects; using System.Data.Entity.Infrastructure; using System.Linq; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { …