I am trying to learn Scala, so I decided to implement data structures with it. I started from the stack. I created the following Stack class.
class Stack[A : Manifest]() { var length:Int = -1 var data = new Array[A](100) /** * Returns the size of the Stack. * @return the size of the stack */ def size = {length} /** * Returns the top element of the Stack without * removing it. * @return Stacks top element (not removed) */ def peek[A] = {data(length)} /** * Informs the developer if the Stack is empty. * @return returns true if it is empty else false. */ def isEmpty = {if(length==0)true else false} /** * Pushes the specified element onto the Stack. * @param The element to be pushed onto the Stack */ def push(i: A){ if(length+1 == data.size) reSize length+=1 data(length) = i; } /** * Pops the top element off of the Stack. * @return the pop'd element. */ def pop[A] = { length-=1 data(length) } /** * Increases the size of the Stack by 100 indexes. */ private def reSize{ val oldData = data; data = new Array[A](length+101) for(i<-0 until length)data(i)=oldData(i) } }
I Then try to initialize this class in my Java class using the following
Stack<Integer> stack = new Stack<Integer>();
However, they tell me that the constructor does not exist and that I must add an argument to match the manifest. Why is this happening and how can I fix it?
Aidanc
source share