15.5 匿名内部类
泛型還可以用于內部類以及匿名內部類
class Customer{
? ? ? private static long counter=1;
? ? ? private final long id=counter++;
? ? ?private Customer(){}
? ? ?public String toString(){return "Customer"+id;}
? ? ?public static Generator<Custom> 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 staic Generator<Teller> generator=nw Generator<Teller>{
? ? ? public Teller next() { return new Teller();}
}
}
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的15.5 匿名内部类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 15.4.5 简化元组的使用
- 下一篇: 15.7 擦除的神秘之处