Scala远程方法注入
我有一个需求,我有一个方法,它接受另一个函数。我想在我的调用者中得到这个参数函数的结果。 我已经为这个场景创建了一个代码片段:Scala远程方法注入,scala,Scala,我有一个需求,我有一个方法,它接受另一个函数。我想在我的调用者中得到这个参数函数的结果。 我已经为这个场景创建了一个代码片段: class ProcessHandler { def executeInstructions(x:String=>Array[String]) { //print the resultant list here } } object ProcessHandlerMain { def main(args: Array[String])
class ProcessHandler {
def executeInstructions(x:String=>Array[String])
{
//print the resultant list here
}
}
object ProcessHandlerMain {
def main(args: Array[String]) {
val handler = new ProcessHandler
handler.executeInstructions( instruction)
}
def instruction(x:String):Array[String] =
{
List("words", "from", "book").toArray
}
}
此调用处理程序。executeInstructions(指令)将由另一个进程执行。这里我使用main方法来测试它
以下是我不知道的:
- 如何打印参数函数的结果
- 如果我必须向客户端公开这个方法executeInstructions(),那么最好的方法是什么?这里我们将不传递文本指令,而是传递一个类似于指令()的函数
class ProcessHandler {
def executeInstructions(x:String=>Array[String])
{
//print the resultant list here
val result = x("some string here")
//this array will be sent to another service
// dispatcher.dispatch(result)
}
}
我的要求已更新:
- 如何打印参数函数的结果:Done
- 如果我必须向客户端公开这个方法executeInstructions(),那么最好的方法是什么?这里我们将不传递文本指令,而是传递一个类似于指令()的函数待定