From Thinking in Java 4th Edition. 泛型实现了:参数化类型的概念,使代码可以应用于多种类型.“泛型”这个术语的意思是:“适用于许多许多的类型”. 如果你了解其他语言(例如: C++)中的参数化类型机制,你就会发现,有些以前能做到的事情,使用Java的泛型机制却无法做到. Java中的泛型需要与C++进行一番比较.了解C++模板的某些方面,有助于你理解泛型的基础.同事,非常重要的一点是:你可以了解Java泛型的局限性是什么,以及为什么会有这些限制.最终是要让你理解…
Memento定义:memento是一个保存另外一个对象内部状态拷贝的对象,这样以后就可以将该对象恢复到原先保存的状态. Memento模式相对也比较好理解,我们看下列代码: public class Originator { private int number; private File file = null; public Originator(){} // 创建一个Memento public Memento getMemento(){ return new Memento(this)…
package xidian.sl.netcredit.util; /** * Copyright (C) 2009-2010 Yichuan, Fuchun All rights reserved. * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this wo…
1.Animal类 package com.yfs.javase; public class Animal { public void cry() { System.out.println("动物叫..."); } } 2.Dog/Cat/Bird类 package com.yfs.javase; public class Dog extends Animal { public void cry() { System.out.println("汪 汪..."); }…
From Thinking in Java 4th Edition 持有对象 // Simple container example (produces compiler warnings.) // {ThrowsException} import java.util.*; class Apple { private static long counter; private final long id = counter++; public long id() { return id;} } c…