I am trying to return ComputingMethod
as a (preferably immutable) List
. I think I want to declare it as an empty list in a separate constructor but I'm not exactly sure how to begin or where to go thereafter.
A simplified version of the code slice I have is:
class MyComputingMethod extends ComputingMethod{
override def execute(o: Vector[Object]): ComputingMethod = {
val wc = List[Object]()
for(i<-o.indices)
wc::(o(i)) //put vector objects in vector
wc
}
}
ComputingMethod
is a trait that defines the execute
method. I've declared Object
in another class. So I want to return a ComputingMethod
object but I need ComputingMethod
to be a List
. I'm not even sure if List
should be declared as generic or as a list of Object
(or as a Vector
of Object
s).
Things I've tried:
object MyComputingMethod {
val mcm = List[Object]() //declaring outside class
type ComputingMethod = List[Object] //also tried within class
val mc = new ComputingMethod().mcm
/*the above doesn't allow me to use any of the List operations,
although mc is of type VirtualMachine,
but the 'mcm' list doesn't seem connected */
}
class MyComputingMethod extends ComputingMethod{
val mcm = List() //declaring outside def
def mCm : MyComputingMethod = List() //def rather than val, shot in the dark
override def execute(o: Vector[Object): ComputingMethod = {
val wc = List[Object]()
for(i<-o.indices)
mCm.wc::(o(i)) //put vector objects in vector
mCm.wc //attempt to return ComputingMethod List
}
}
So I think what I I need to do is create a generic constructor (and a private?) for MyComputingMethod that within it initializes an empty list that I can use as a MyComputingMethod object, But I am unsure how to do this. Any suggestions are much appreciated.