You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assuming you compiled the following Scala code like (on a Mac with Scala 2.12.1 and Java 1.8.0_112):
$ echo > Dog.scala <<EOF
class Dog(name:String, age:Int) {
println("Dog is created!")
def sayHello() = println(s"My name is $name, I am $age years old")
}
EOF
$ scalac Dog.scala
Then a Dog.class file is created. Decompiling it with the JD-GUI version 1.4.0 brings the following output:
import scala.Predef.;
import scala.StringContext;
import scala.reflect.ScalaSignature;
import scala.runtime.BoxesRunTime;
@ScalaSignature(bytes="\006\001-2A!\001\002\001\013\t\031Ai\\4\013\003\r\tq\001P3naRLhh\001\001\024\005\0011\001CA\004\013\033\005A!\"A\005\002\013M\034\027\r\\1\n\005-A!AB!osJ+g\r\003\005\016\001\t\005\t\025!\003\017\003\021q\027-\\3\021\005=1bB\001\t\025!\t\t\002\"D\001\023\025\t\031B!\001\004=e>|GOP\005\003+!\ta\001\025:fI\0264\027BA\f\031\005\031\031FO]5oO*\021Q\003\003\005\t5\001\021\t\021)A\0057\005\031\021mZ3\021\005\035a\022BA\017\t\005\rIe\016\036\005\006?\001!\t\001I\001\007y%t\027\016\036 \025\007\005\032C\005\005\002#\0015\t!\001C\003\016=\001\007a\002C\003\033=\001\0071\004C\003'\001\021\005q%\001\005tCfDU\r\0347p)\005A\003CA\004*\023\tQ\003B\001\003V]&$\b")
public class Dog
{
private final String name;
public Dog(String name, int age)
{
Predef..MODULE$.println("Dog is created!");
}
public void sayHello()
{
Predef..MODULE$.println(new StringContext(Predef..MODULE$.wrapRefArray((Object[])new String[] { "My name is ", ", I am ", " years old" })).s(Predef..MODULE$.genericWrapArray(new Object[] { this.name, BoxesRunTime.boxToInteger(this.age) })));
}
}
There is clearly a private final int age field missing. You can validate that easily by using javap like:
$javap -private Dog.class
Compiled from "Dog.scala"
public class Dog {
private final java.lang.String name;
private final int age;
public void sayHello();
public Dog(java.lang.String, int);
}
Assuming you compiled the following Scala code like (on a Mac with Scala 2.12.1 and Java 1.8.0_112):
Then a
Dog.class
file is created. Decompiling it with the JD-GUI version 1.4.0 brings the following output:There is clearly a
private final int age
field missing. You can validate that easily by usingjavap
like:See also: http://stackoverflow.com/questions/41561061/scala-primary-constructor-does-not-generate-field
The text was updated successfully, but these errors were encountered: