匿名內部類泛型

u010660276發表於2014-01-13
import java.util.*;
interface Generator<T>{
	T next();
}
class Customer{
	private static long counter=1;
	private final long id=counter++;
	private Customer(){}
	public String toString(){
		return "Customer "+id;
	}
	public static Generator<Customer> generator(){
		return new Generator<Customer>(){
			public Customer next(){
				return new Customer();
			}
		};
	}
}
class Teller{
	private static long counter=1;
	private final long id=counter++;
	private Teller(){}
	public String toString(){
		return "Teller "+id;
	}
	public static Generator<Teller> generator=new Generator<Teller>(){
		public Teller next(){
			return new Teller();
		}
	};
}

public class BankTeller {

	public static void serve(Teller t,Customer c){
		System.out.println(t+" server "+c);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Random rand=new Random(47);
		Queue<Customer> line=new LinkedList<Customer>();
		//do something

	}

}

相關文章