Java’s javap command doesn’t show private members (by default)

As I was just reminded, Java’s javap command doesn’t show private members by default. You have to use the -p option of javap to see private members.

I was just reminded of that when using the Scala REPL. Given this Person class with a private constructor field named name:

class Person(private var name: String)

javap without the -p option shows this:

scala> :javap -c Person
Compiled from "<console>"
public class $line3.$read$$iw$$iw$Person {
  public $line3.$read$$iw$$iw$Person(java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field name:Ljava/lang/String;
       5: aload_0
       6: invokespecial #27                 // Method java/lang/Object."<init>":()V
       9: return
}

But javap -p shows the private fields related to name, which I’ve made bold below:

scala> :javap -p Person
Compiled from "<console>"
public class $line3.$read$$iw$$iw$Person {
  private java.lang.String name;
  private java.lang.String name();
  private void name_$eq(java.lang.String);
  public $line3.$read$$iw$$iw$Person(java.lang.String);
}

As shown, this includes the private name field, the getter method named name() and the setter method that shows up with the funky name name_$eq.