protected abstract DB createResource(Object owner, String iDatabaseName, Object... iAdditionalArgs);(DB爲類中聲明的類型參數,其中與Scala代碼不一樣的有
【3】可變參數Object...,翻譯成Scala就是AnyRef*) ide
def createResource(owner: Any, iDatabaseName: String, iAdditionalArgs: Array[AnyRef]): OObjectDatabaseTx = ???這時候編譯器還不認這個方法,所以須要簡單改造一下:前面加上override和protected修飾符,並將Array[AnyRef]改成AnyRef*。而後這個方法就能經過編譯了。
override protected def createResource(owner: Any, iDatabaseName: String, iAdditionalArgs: AnyRef*): OObjectDatabaseTx = ???這時候咱們會發現參數列表中的Object被翻譯爲Any,而Object...被翻譯成AnyRef*。爲了驗證二者的差別,我把owner的類型改成AnyRef,保存編譯,編譯器立刻報出異常:
error: method createResource overrides nothing. Note: the super classes of class OObjectDatabasePool contain the following, non final members named createResource: protected[package db] def createResource(x$1: Any,x$2: String,x$3: <repeated...>[Object]): org.misty.orient.object.db.OObjectDatabaseTx override protected def createResource(owner: AnyRef, iDatabaseName: String, iAdditionalArgs: AnyRef*): OObjectDatabaseTx = ???
protected[package db] def createResource(x$1: Any,x$2: String,x$3: <repeated...>[Object]):而子類提供的倒是:
override protected def createResource(owner: AnyRef, iDatabaseName: String, iAdditionalArgs: AnyRef*): OObjectDatabaseTx = ???二者沒法匹配致使沒法編譯。因爲咱們是修改了參數列表中的第一個參數的類型致使的錯誤,所以只需將第一個參數的類型改回Any便可,同時可見雖然咱們將方法的包訪問權限縮小了(從protected[package db]縮小爲protected),但編譯器並非很介意。