- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在为 ScalaTest 开发一个客户可读的 DSL。目前我可以写
feature("Admin Login") {
scenario("Correct username and password") {
given("user visits", classOf[AdminHomePage])
then(classOf[SignInPage], "is displayed")
feature("Admin Login") {
scenario("Correct username and password") {
given("user visits", the[AdminHomePage])
then(the[SignInPage], "is displayed")
def the[T] =
classOf[T]
?
最佳答案
你可以试试这个:
def the[T: ClassManifest]: Class[T] =
classManifest[T].erasure.asInstanceOf[Class[T]]
[T: ClassManifest]
是
context bound相当于:
def the[T](implicit classManifest: ClassManifest[T])
Manifest[T]
的隐式值和
ClassManifest[T]
由编译器自动填充(如果它可以具体化传递给方法的类型参数)并为您提供有关
T
的运行时信息:
ClassManifest
仅将其删除为
Class[_]
, 和
Manifest
另外可以通知您有关
T
的可能参数化本身(例如,如果
T
是
Option[String]
,那么您也可以了解
String
部分)。
关于scala - 在 Scala 中重命名 classOf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6290480/
如何声明expectedException,才能只传递Exception和子类?目前我正在使用 expectedException: Any。 详细信息。 我有一个像这样调用的测试实用程序方法, as
我正在尝试使用 scala/java 创建一个用于对象更新的通用方法,但我无法获取类型参数的类。 这是我的代码: object WorkUnitController extends Controlle
我有以下代码: class ServletSpec extends Specification { def createServlet[T <: HttpServlet](clazz: Cla
我需要在用 Java 编写的类上调用 classOf,如下所示: public class Order {...} 其中Item如下所示 public class Item {...} 然后我需要将
我正在为 ScalaTest 开发一个客户可读的 DSL。目前我可以写 feature("Admin Login") { scenario("Correct username and passwo
我想知道如何在 Scala 中获取对象类型的类对象。好吧,由于对象的双重含义,这是满嘴的。所以这里有一个会失败的例子: object Main { private [this] val TAG
让我举个例子来解释我想做什么(或者至少知道这是否可行): 在 Clang 中,让我们使用一些基本的 ValueDecl .正如您在提供的链接中所见,此 ValueDecl 可以: 做一个简单的Valu
我正在尝试将JUnit从4.10升级到5.3.1一个Scala项目。该项目正在使用Scalatest。我想知道现在应该用以下代码替换什么: @RunWith(classOf[JUnitRunner])
Here ,我想知道如何实现Collection#toArray(T[] array)适本地。我最生气的是array.getClass().getComponentType()类型为Class而不是C
我有这个代码 "123".getClass.asInstanceOf[Class[String]] "123".getClass.asInstanceOf[classOf[String]]//comp
用Java编写简单的Map Reduce程序时,下面的行可以正常工作。 job.setOutputFormatClass(TextOutputFormat.class) 但是Scala中的同一件
在我的示例中,我希望能够返回类 Of[frame] 而不是我得到一个错误未找到:输入 frame。 trait User extends VertexFrame { ... } object Us
我在scala中遇到了一些非常奇怪的行为。 我编写了一个通用方法,该方法将容易出错的代码和“有效异常”列表作为参数,并且应该执行该代码,同时在抛出“有效异常”时重试该代码。 该方法很好用,我在几个地方
我有一个来自 Java 的接口(interface) public class IJava { ... public java.lang.Class getType(); ... }
我在 XMLIO.scala 中定义了自定义输入和输出格式: import scala.xml.Node import org.apache.hadoop.lib.input.FileInputFor
我写了一小段测试代码,正在用 IntelliJ IDEA 12 CE 编译它 import com.twitter.common.zookeeper.ZooKeeperClient import or
我是一名优秀的程序员,十分优秀!