小编ret*_*nym的帖子

处理容器停止/重新加载事件

有一个提升应用程序在Boot.scala中启动ssh守护程序.这是问题:当我container:restart /在sbt会话中运行时,我在使用异常中获得地址.现在有两个问题:

  1. 在Boot.scala中启动依赖服务是正确的方法吗?
  2. 无论如何如何处理容器:停止事件?

scala lift sbt xsbt-web-plugin

5
推荐指数
1
解决办法
749
查看次数

如何绑定scala的heredoc中的数据?

val name = "mike"
val str = """Hi, {name}!"""
println(str)
Run Code Online (Sandbox Code Playgroud)

我希望它输出str as Hi, mike!,但失败了.这该怎么做?

scala heredoc rawstring

3
推荐指数
2
解决办法
1002
查看次数

Scala:一个声明自己为变量的类

我正在尝试在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)

tree types scala path covariance

1
推荐指数
1
解决办法
322
查看次数

Scala期望异常片段

我正在尝试模拟常见测试框架(例如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 pattern-matching type-erasure

0
推荐指数
1
解决办法
891
查看次数