有一个提升应用程序在Boot.scala中启动ssh守护程序.这是问题:当我container:restart /在sbt会话中运行时,我在使用异常中获得地址.现在有两个问题:
val name = "mike"
val str = """Hi, {name}!"""
println(str)
Run Code Online (Sandbox Code Playgroud)
我希望它输出str as Hi, mike!,但失败了.这该怎么做?
我正在尝试在scala中创建一个二叉树,并且需要为它创建一个方法,所以我试图在类中处理子项和子项.我想让父树成为一个树,以便我可以在另一个名为getPath的函数中递归调用它,但我不能在Tree类中创建一个Tree.这是代码:
case class Tree[+T](value: T, left: Option[Tree[T]], right: Option[Tree[T]]) {
var parent: Tree[T] = null
//method for setting the parent of tree.
//this method returns the parent TREE instead of the parent value
//so if you want to use it to find the value, you need to get the parent.value
def setParent(tree: Tree[T]) {
parent = tree
}
//method for returning the parent
//the parent is a tree so you have to .value it to get the root
def getParent(): …Run Code Online (Sandbox Code Playgroud) 我正在尝试模拟常见测试框架(例如JUnit或TestNG)的预期异常行为.
到目前为止,这是我能想到的(工作):
trait ExpectAsserts
{
self : {
def fail (message : String)
def success (message : String)
} =>
def expect[T](exceptionClass : Class[T])(test : => Unit)
{
try
{
test
fail("exception not thrown")
}
catch
{
case expected : T => success("got exception " + expected)
case other : Exception => fail("expected "+ exceptionClass + " but " + other + " thrown instead.")
}
}
}
object Main extends ExpectAsserts
{
def main (args : Array[String])
{
expect(classOf[ArithmeticException]) …Run Code Online (Sandbox Code Playgroud) scala ×4
covariance ×1
heredoc ×1
lift ×1
path ×1
rawstring ×1
sbt ×1
tree ×1
type-erasure ×1
types ×1