How to investigate objects/types/etc. from Scala REPL?

前端 未结 4 1782
长发绾君心
长发绾君心 2020-12-22 23:59

I\'ve been working with Scala for a while now and have written a 10,000+ line program with it, but I\'m still confused by some of the inner workings. I came to Scala from Py

4条回答
  •  有刺的猬
    2020-12-23 00:35

    You need to pass fully qualified class name to javap.

    First take it using classOf:

    scala> classOf[List[_]]
    res2: java.lang.Class[List[_]] = class scala.collection.immutable.List
    

    Then use javap (doesn't work from repl for me: ":javap unavailable on this platform.") so example is from a command line, in repl, I believe, you don't need to specify classpath:

    d:\bin\scala\scala-2.9.1-1\lib>javap -classpath scala-library.jar "scala.collection.immutable.List"
    

    But I doubt this will help you. Probably you're trying to use techniques you used to use in dynamic languages. I extremely rarely use repl in scala (while use it often in javascript). An IDE and sources are my all.

提交回复
热议问题