I am using the :javap command in the scala repl and was trying to look at the traits companion object, but I couldn't seem to find out how. Here is what I do from command line.
$ cat > Foo.scala <<EOF
trait Foo {
def foo: String
def echo = println(foo)
}
EOF
$ scalac Foo.scala
$ javap Foo.class
Compiled from "Foo.scala"
public abstract class Foo$class {
public static void echo(Foo);
public static void $init$(Foo);
}
$ javap Foo\$class.class
Compiled from "Foo.scala"
public abstract class Foo$class {
public static void echo(Foo);
public static void $init$(Foo);
}
I try the same in the repl and get the following (using Bar since Foo will be compiled in ., so repl will pick it up)
scala> trait Bar {
| def bar: String
| def echo = println(bar)
| }
defined trait Bar
scala> :javap Bar
Compiled from "<console>"
public interface Bar{
public abstract java.lang.String bar();
public abstract void echo();
}
scala> :javap Bar$class
Failed: Could not find class bytes for 'Bar$class'
Scala version of repl
$ scala -version
Scala code runner version 2.10.2 -- Copyright 2002-2013, LAMP/EPFL
Running on a mac
EDIT: Just downloaded scala 2.11 and ran the repl there. It seems that :javap is able to pick up the class, but its running :javap -v rather than :javap. Switching to :javap -p makes this output the same as 2.10