I have a break point set at line s = new Array(capacity)
but it seems like the apply method is not being called. Have I implemented it correctly ?
object StacksAndQueuesTest {
def main(args: Array[String]) {
val f = new FixedCapacityStackOfStrings(3)
println(f.isEmpty);
}
}
class FixedCapacityStackOfStrings(capacity : Int) {
var s : Array[String] = _
var N : Int = 0
def isEmpty : Boolean = {
N == 0
}
def push(item : String) = {
this.N = N + 1
s(N) = item
}
def pop = {
this.N = N - 1
val item : String = s(N)
/**
* Setting this object to null so
* that JVM garbage collection can clean it up
*/
s(N) = null
item
}
object FixedCapacityStackOfStrings {
def apply(capacity : Int){
s = new Array(capacity)
}
}
}