author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Wed, 10 Jun 2015 14:51:35 +0100 | |
changeset 79 | ca8f9645db69 |
parent 44 | a751aa1ee4f7 |
permissions | -rw-r--r-- |
44 | 1 |
package Main |
2 |
||
3 |
class Stack[T] { |
|
4 |
var elems: List[T] = Nil |
|
5 |
def push(x: T) { elems = x :: elems } |
|
6 |
def top: T = elems.head |
|
7 |
def pop() { elems = elems.tail } |
|
8 |
} |
|
9 |
||
10 |
object GenericsTest extends App{ |
|
11 |
val stack = new Stack[Int] |
|
12 |
stack.push(1) |
|
13 |
stack.push('a') |
|
14 |
println(stack.top) |
|
15 |
stack.pop() |
|
16 |
println(stack.top) |
|
17 |
} |