Fahad/CodeSamples/GenericClasses.scala
changeset 44 a751aa1ee4f7
equal deleted inserted replaced
43:10e7a90d8e7a 44:a751aa1ee4f7
       
     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 }