私は ScalaInAction に取り組んでいます (本はまだ MEAP ですが、コードは github で公開されています) 現在、この restClient を見ている第 2 章にいます: : https://github.com/nraychaudhuri/scalainaction/blob/master/ chap02/RestClient.scala
まず、scala 拡張機能を使用して intelliJ をセットアップし、次のように HelloWorld を作成しましたmain()
。
<ALL the imports>
object HelloWorld {
def main(args: Array[String]) {
<ALL the rest code from RestClient.scala>
}
}
コンパイル時に次のエラーが発生します。
scala: forward reference extends over defintion of value command
val httppost = new HttpPost(url)
^
def
これを修正するには、次の行を移動して、の順序付けが正しくなるようにします。
require( args.size >= 2, "You need at least two arguments to make a get, post, or delete request")
val command = args.head
val params = parseArgs(args)
val url = args.last
command match {
case "post" => handlePostRequest
case "get" => handleGetRequest
case "delete" => handleDeleteRequest
case "options" => handleOptionsRequest
}
github ページを閲覧しているときに、これを見つけました: https://github.com/nraychaudhuri/scalainaction/tree/master/chap02/restclient
extends App
メソッドの代わりにRestClient.scala を使用して実装するmain()
もの:
<All the imports>
object RestClient extends App {
<All the rest of the code from RestClient.scala>
}
次に、メソッドを実装する代わりにobject HelloWorld
使用するように変更しましたが、エラーなしで動作しますextends App
main()
main()
これを行う方法でエラーが発生するのに、エラーが発生しないのはなぜextends App
ですか?