小编Jan*_*cki的帖子

如何将Scala方法参数限制为classOf [Exception]或classOf [Exception的子类型]

如何声明expectedException以便只传递异常和子类?目前我正在使用expectedException: Any.

细节.

我有一个像这样调用的测试实用程序方法,

assertExceptionThrown("En-passant should be rejected when the previous move was not a double advance", classOf[UnreachablePositionException] ) {
  e.rejectIllegalMove(EnPassant("e5", "d6"))
}
Run Code Online (Sandbox Code Playgroud)

第一个参数列表的第二个参数是classOf [SomeException].这是测试方法的签名,

  // TODO: Restrict expectedException to Exception or subclass
  def assertExceptionThrown(assertion: String, expectedException: Any)(b:  => Unit) {
Run Code Online (Sandbox Code Playgroud)

我的问题是如何声明expectedException,以便只传递异常和子类?目前我正在使用expectedException:Any.

测试特征的完整来源在这里, https://github.com/janekdb/stair-chess/blob/master/src/test/Test.scala

types scala exception

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

如何将变换的参数提供给超类构造函数,同时避免使用Scala进行内联计算

这是我目前不能令人满意的解决方案,在传递给超类构造函数之前操纵传递给子类构造函数的值的问题,

class MissingItemsException(items: Set[String], itemsCategory: String)
  extends RuntimeException(MissingItemsException.makeMessage(items, itemsCategory))

private object MissingItemsException {

  private def makeMessage(items: Set[String], itemsCategory: String): String = {
    /* Format set as ['?','?','?'] */
    val Items = items mkString ("['", "','", "']")
    "the following items %s were missing from '%s'" format (items, itemsCategory)
  }

}
Run Code Online (Sandbox Code Playgroud)

是否有一种方法可以分解转换,以便转换代码保持接近使用点,同时保持代码清晰?

constructor scala params

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

朱莉娅有三元条件算子吗?

Python,Java和Scala都有三元运算符.朱莉娅的等价物是什么?

ternary-operator julia

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

Neo4j 浏览器 AUTO-COMPLETE 切换是否存在于 3.2.0 中?

根据Nodes() 函数返回关系?Neo4j 浏览器中有一个 AUTO-COMPLETE 开关。我正在使用没有这个的 3.2.0。是否有等效的 UI 元素?

neo4j

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

标签 统计

scala ×2

constructor ×1

exception ×1

julia ×1

neo4j ×1

params ×1

ternary-operator ×1

types ×1