🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #114

����Object�������

#114
From: flysky
Date: Thu, 29 Oct 2009 14:11
36 lines
2258 bytes
��̴�ţ�������public Object top()Ϊʲô���ܷ���Object������Eclipse������˵Can't convert from Object to Object;
���public void push(Object element)����Ҳ�޷���ӡ�
Object�಻��������ĸ�����Ϊʲô��������������أ�
package study;
import java.util.LinkedList;
import java.util.*;
//������ʹ��LinkedListʵ��һ����ջ
class LinkedListStack {// ��ջ�ڲ�ʹ��һ��LinkedList�������Ԫ��
	private LinkedList data = new LinkedList<String>();
	public boolean isEmpty() {
		return data.isEmpty();
	}
	public Object top() {// ȡջ��Ԫ���൱��ȡLinkedList������ͷλ�õ�Ԫ��
		return data.getFirst();
	}
	public void push(Object element) {// ѹ��Ԫ���൱����LinkedList������ͷλ�ò���Ԫ��
		data.addFirst(element);
	}
	public void pop() {// ����Ԫ���൱��ɾ��LinkedList������ͷλ�õ�Ԫ��
		data.removeFirst();
	}
}
public class LinkedListDemo {
	public static void main(String[] args) {
		LinkedListStack stack = new LinkedListStack();// ��������ʹ����LinkedListʵ�ֵĶ�ջ���÷�
		stack.push("C++");
		stack.push("C#");
		stack.push("Java");
		while (! stack.isEmpty()) {
			System.out.println(stack.top());
			stack.pop();
		}
	}
}
--
�� ��Դ:�������ʵBBS http://bbs.tju.edu.cn [FROM: 202.113.182.86]
Technical Details
Message-ID: <4iaP8j$AGI@bbs.tju.edu.cn>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsgate.cuhk.edu.hk!news.neu.edu.cn!news.byr.edu.cn!TJU

Show Full Headers
Complete Article Headers
X-Google-Thread: d1247dbd28,6ed0f8c68d5e3973,start
X-Google-Attributes: gidd1247dbd28,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: Chinese,GB
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news.glorb.com!newsgate.cuhk.edu.hk!news.neu.edu.cn!news.byr.edu.cn!TJU
From: xiangtian.bbs@bbs.tju.edu.cn.no.spam (flysky)
Newsgroups: cn.bbs.comp.lang.java
Subject: ����Object�������
Date: 29 Oct 2009 14:11:57 GMT
Organization: �����ʵBBSվ
Message-ID: <4iaP8j$AGI@bbs.tju.edu.cn>
Mime-Version: 1.0
Content-Type: text/plain; charset="gb2312"
Content-Transfer-Encoding: 8bit
X-Filename: Java/M.1256825517.A