scala> class Department( val departmentId: Int, val departmentName: String)
defined class Department
scala> javap -p Department
<console>:12: error: not found: value javap
javap -p Department
^
<console>:12: error: not found: value p
javap -p Department
^
Asked
Active
Viewed 597 times
-2

Andrey Tyukin
- 43,673
- 4
- 57
- 93

Mayank Kishore
- 1
- 1
-
What you are trying to do does not make any sense. Scala REPL evaluates pieces of scala code, it does not know anything about `javap` or any other external commands available on the usual command line. You can invoke shell commands with `:sh`, but it won't help here either, because the REPL does not produce any files like `Department.class` while compiling the input, it keeps the representation of the `Department` class in memory. You can use the `:javap` REPL command, though. – Andrey Tyukin Aug 06 '18 at 14:43
-
Thanks for quick response!! I am thinking that the class Department is compiled and when i will use javap then it should show the class information. – Mayank Kishore Aug 06 '18 at 14:47
1 Answers
2
You cannot invoke javap
program as if you are in the normal shell, because the Scala REPL is not a shell.
You can use the built-in command :javap
though:
scala> class Department( val departmentId: Int, val departmentName: String)
defined class Department
scala> :javap -p Department
Compiled from "<console>"
public class $line4.$read$$iw$$iw$Department {
private final int departmentId;
private final java.lang.String departmentName;
public int departmentId();
public java.lang.String departmentName();
public $line4.$read$$iw$$iw$Department(int, java.lang.String);
}
From the REPL :help
:
:javap <path|class>
disassemble a file or class name

Andrey Tyukin
- 43,673
- 4
- 57
- 93
-
Now getting another error. Failed: No javap tool available: scala.tools.nsc.interpreter.JavapClass$JavapTool6 failed to initialize. – Mayank Kishore Aug 06 '18 at 15:10
-
@MayankKishore Check the java versions then. Could it be that you are using some very old scala interpreter? [Question with very similar error](https://stackoverflow.com/questions/39629223/no-javap-tool-not-found-in-scala-repl?rq=1). – Andrey Tyukin Aug 06 '18 at 15:15