Private methods in interfaces likely to be supported on JVM9

149 views
Skip to first unread message

Simon Ochsenreither

unread,
Mar 17, 2015, 2:10:37 PM3/17/15
to scala-i...@googlegroups.com
Not sure if this is news or well-known, but it seems to ship with JDK9 build 54 and later: http://mail.openjdk.java.net/pipermail/jdk9-dev/2015-March/001981.html

Dmitry Petrashko

unread,
Mar 25, 2015, 8:04:41 AM3/25/15
to scala-i...@googlegroups.com
Hi Simon,

Private methods interfaces are already supported by JVM.
The message that you refer to is about support in javac, not in the VM. In VM it's already supported and emitted by dotty.

cat A.scala
trait A{
  private def p = "s"
  def d = p
}

object B extends A{
  def main(args: Array[String]): Unit = {
    println(d)
  }
}
dotc A.scala
javap -c -p A
Compiled from "A.scala"
public interface A {
  public A initial$A();
    Code:
       0: aload_0
       1: areturn

  private java.lang.String p();
    Code:
       0: ldc           #13                 // String s
       2: areturn

  public java.lang.String d();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method p:()Ljava/lang/String;
       4: areturn
}
javap -c -p B$
ompiled from "A.scala"
public final class B$ implements A {
  public static final B$ MODULE$;

  public static {};
    Code:
       0: new           #2                  // class B$
       3: invokespecial #14                 // Method "<init>":()V
       6: return

  public B$();
    Code:
       0: aload_0
       1: invokespecial #15                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: putstatic     #17                 // Field MODULE$:LB$;
       8: aload_0
       9: invokespecial #21                 // Method A.initial$A:()LA;
      12: pop
      13: return

  public void main(java.lang.String[]);
    Code:
       0: getstatic     #29                 // Field scala/Predef$.MODULE$:Lscala/Predef$;
       3: aload_0
       4: invokeinterface #33,  1           // InterfaceMethod A.d:()Ljava/lang/String;
       9: invokevirtual #37                 // Method scala/Predef$.println:(Ljava/lang/Object;)V
      12: return
}
 
Cheers,
Dmitry

Simon Ochsenreither

unread,
Mar 25, 2015, 7:56:15 PM3/25/15
to scala-i...@googlegroups.com
Wow, I wasn't aware of this!

Thanks a lot for the correction!
Reply all
Reply to author
Forward
0 new messages