How to learn about using scala.None from Java using javap?

后端 未结 2 363
灰色年华
灰色年华 2021-01-29 19:26

In a previous question, Accessing scala.None from Java, it seems that people had used javap to figure out how to access scala.None from Java.

2条回答
  •  不思量自难忘°
    2021-01-29 19:59

    I'm not competing with the other answer, but since people seem often not to notice this, you can do this in the repl.

    scala> :paste
    // Entering paste mode (ctrl-D to finish)
    
    object OptionTest extends App {
      val x = scala.None
      val y = scala.Some("asdf")
    }
    
    // Exiting paste mode, now interpreting.
    
    defined module OptionTest
    
    scala> :javap -v OptionTest$
    Compiled from ""
    public final class OptionTest$ extends java.lang.Object implements scala.App,scala.ScalaObject
      SourceFile: ""
      Scala: length = 0x
    
      [lots of output etc]   
    
      public scala.None$ x();
        Code:
         Stack=1, Locals=1, Args_size=1
         0: aload_0
         1: getfield    #65; //Field x:Lscala/None$;
         4: areturn
    

提交回复
热议问题