English 中文(简体)
Scala: 如果没有界定任何类别,是否有违约类别?
原标题:Scala: Is there a default class if no class is defined?
  • 时间:2011-09-02 06:10:05
  •  标签:
  • scala
最佳回答

REPL将你的所有发言(实际上改写了你的发言稿)以自动作成。 如果你使用<条码>-X印:typer 备选办法印刷中间代码,你可以认为该代码是有效的:

scala> def hoho(str:String) = {println("hoho " + str)}
[[syntax trees at end of typer]]// Scala source: <console>
package $line1 {
  final object $read extends java.lang.Object with ScalaObject {
    def this(): object $line1.$read = {
      $read.super.this();
      ()
    };
    final object $iw extends java.lang.Object with ScalaObject {
      def this(): object $line1.$read.$iw = {
        $iw.super.this();
        ()
      };
      final object $iw extends java.lang.Object with ScalaObject {
        def this(): object $line1.$read.$iw.$iw = {
          $iw.super.this();
          ()
        };
        def hoho(str: String): Unit = scala.this.Predef.println("hoho ".+(str))
      }
    }
  }
}

So your method hoho is really $line1.$read.$iw.$iw.hoho. Then when you use hoho("foo") later on, it ll rewrite to add the package and outer objects.

附加说明:关于字母,-Xprint:typer(-Xprint:parser/code>)显示,该代码在main(args:Array[String]的正标栏内封顶内。 可查阅<代码>argsargv

问题回答

暂无回答




相关问题
How to flatten a List of different types in Scala?

I have 4 elements:List[List[Object]] (Objects are different in each element) that I want to zip so that I can have a List[List[obj1],List[obj2],List[obj3],List[obj4]] I tried to zip them and I ...

To use or not to use Scala for new Java projects? [closed]

I m impressed with Twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java? EDIT: And, ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Include jar file in Scala interpreter

Is it possible to include a jar file run running the Scala interpreter? My code is working when I compile from scalac: scalac script.scala -classpath *.jar But I would like to be able to include a ...

Scala and tail recursion

There are various answers on Stack Overflow which explain the conditions under which tail recursion is possible in Scala. I understand the limitations and how and where I can take advantage of tail ...

热门标签