Estoy intentando aprender Scala, así que he decidido implementar las estructuras de datos con él. Empecé con la Pila. Creé la siguiente clase de Pila.Intento de inicializar una clase creada por Scala en Java
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)
}
}
que luego intentar inicializar esta clase en mi clase de Java utilizando la siguiente
Stack<Integer> stack = new Stack<Integer>();
Sin embargo, me han dicho que el constructor no existe y que yo debería añadir un argumento para que coincida Manifiesto. ¿Por qué sucede esto y cómo puedo solucionarlo?
+1 para la explicación, pero es posible crear el 'Manifiesto' sin la magia del compilador. Ver mi respuesta – paradigmatic