
| package com.heatonresearch.examples.collections; public class Example<ONE, TWO, THREE> { private ONE one; private TWO two; private THREE three; public ONE getOne() { return one; } public void setOne(ONE one) { this.one = one; } public THREE getThree() { return three; } public void setThree(THREE three) { this.three = three; } public TWO getTwo() { return two; } public void setTwo(TWO two) { this.two = two; } public static void main(String args[]) { Example<Double, Integer, String> example = new Example<Double, Integer, String>(); example.setOne(1.5); example.setTwo(2); example.setThree("Three"); } } |
| Example example=new Example(); |
| example.setOne(1.5); example.setTwo(2); example.setThree("Three"); |
| package com.heatonresearch.examples.collections; import java.util.*; public class Queue { private ArrayList list = new ArrayList(); public void push(T obj) { list.add(obj); } public T pop() throws QueueException { if (size() == 0) throw new QueueException( "Tried to pop something from the queue, " + "when it was empty"); T result = list.get(0); list.remove(0); return result; } public boolean isEmpty() { return list.isEmpty(); } public int size() { return list.size(); } public void clear() { list.clear(); } } |
| public class Queue |
| package com.heatonresearch.examples.collections; public class QueueException extends Exception { public QueueException(String msg) { super(msg); } } |
| if (size() == 0) throw new QueueException("Tried to pop something from the queue, " + "when it was empty"); |
| T result = list.get(0); list.remove(0); return result; |
| 关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图 |
| Copyright © 2000-2008 , www.21tx.com , All Rights Reserved . |
| © 晨新科技 版权所有 Created by TXSite.net |