在scala内部调用mechanize失败:无法将HtmlDocument转换为scala.runtime.Nothin

在scala内部调用mechanize失败:无法将HtmlDocument转换为scala.runtime.Nothin,scala,Scala,我有以下代码要使用mechanize(可以从下载) 它没能说出下面的话,我怎样才能让它工作 scala> agent.get("http://www.ask.com") java.lang.ClassCastException: com.gistlabs.mechanize.document.html.HtmlDocument cannot be cast to scala.runtime.Nothing$ at .<init>(<console>:12)

我有以下代码要使用mechanize(可以从下载)

它没能说出下面的话,我怎样才能让它工作

scala> agent.get("http://www.ask.com")
java.lang.ClassCastException: com.gistlabs.mechanize.document.html.HtmlDocument cannot be cast to scala.runtime.Nothing$
    at .<init>(<console>:12)
    at .<clinit>(<console>)
    at .<init>(<console>:7)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
scala>agent.get(“http://www.ask.com")
java.lang.ClassCastException:com.gistlabs.mechanize.document.html.HtmlDocument不能强制转换为scala.runtime.Nothing$
在。(:12)
在
在。(:7)
在
$print()
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处
在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)中
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)中
位于java.lang.reflect.Method.invoke(Method.java:606)

问题在于
MechanizeAgent。get
是一种通用方法(请参阅)。因此,您必须告诉Scala所期望的类型。要么像这样:

import com.gistlabs.mechanize._
import com.gistlabs.mechanize.document._

val agent = new MechanizeAgent();
val page = agent.get[Document]("http://www.ask.com");
import com.gistlabs.mechanize._
import com.gistlabs.mechanize.document._

val agent = new MechanizeAgent();
val page: Document = agent.get("http://www.ask.com");
或者像这样:

import com.gistlabs.mechanize._
import com.gistlabs.mechanize.document._

val agent = new MechanizeAgent();
val page = agent.get[Document]("http://www.ask.com");
import com.gistlabs.mechanize._
import com.gistlabs.mechanize.document._

val agent = new MechanizeAgent();
val page: Document = agent.get("http://www.ask.com");