码迷,mamicode.com
首页 > 编程语言 > 详细

java 参数化类型

时间:2015-01-15 00:09:58      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 1 package com.gxf.collection;
 2 
 3 import java.util.LinkedList;
 4 
 5 public class TestForT<T> {
 6     private LinkedList<T> storage = new LinkedList<T>();
 7     
 8     /**
 9      * 压栈操作
10      * @param element
11      */
12     public void push(T element){
13         storage.addFirst(element);
14     }
15     /**
16      * 出栈
17      * @return
18      */
19     public T pop(){
20         return storage.removeFirst();
21     }
22     
23     /**
24      * 判断栈是否为空
25      * @return
26      */
27     public boolean isEmpty(){
28         return storage.isEmpty();
29     }
30 
31     public static void main(String[] args) {
32         TestForT<Integer> stack = new TestForT<Integer>();
33         stack.push(1);
34         stack.push(2);
35         stack.push(3);
36         stack.push(4);
37         stack.push(5);
38         
39         while(!stack.isEmpty()){
40             System.out.println(stack.pop());
41         }
42     }
43 
44 }

output:

5
4
3
2
1

java 参数化类型

标签:

原文地址:http://www.cnblogs.com/luckygxf/p/4225170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!