21

I know about the usage difference between empty-parameter and parameterless methods in scala, and my question pertains to the class file generated. When I look at these two classes in javap, they look exactly the same:

class Foo {
  def bar() = 123;
}


class Foo {
  def bar = 123;
}

But when I look at them in scalap, they accurately reflect the parameter lists. Where in the class file is scalac making this distinction known?

Chuck Adams
  • 777
  • 6
  • 18

1 Answers1

20

In the .class file, there is a class file attribute called ScalaSig, which contains all of the extra information needed by Scala. It's not really readable by humans, but it is there:

$ javap -verbose Foo.class
const #195 = Asciz      ScalaSig;
const #196 = Asciz      Lscala/reflect/ScalaSignature;;
const #197 = Asciz      bytes;
const #198 = Asciz      ^F^A!3A!^A^B^A^S\t\tb)^[7f^Y^Vtw\r^^5DQ^V^\7.^Z:^K^E\r!^
Q^A^B4jY^VT!!^B^D^B^UM^\^W\r\1tifdWMC^A^H^....

See also How is the Scala signature stored? and scala.reflect.ScalaSignature, which isn't very interesting :-)

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171
  • Thanks! For some reason, -verbose never jumped out at me from the javap manpage, and as you said, it isn't the most human-readable thing in the world :) – Chuck Adams Apr 12 '12 at 19:32