Skip to content

Instantly share code, notes, and snippets.

@non
Created October 26, 2014 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save non/1f8e540f3d3df13b0a64 to your computer and use it in GitHub Desktop.
Save non/1f8e540f3d3df13b0a64 to your computer and use it in GitHub Desktop.
Comparison of different constructor strategies.
package test
abstract class Cat1(val name: String, val age: Int)
class Tabby1(override val name: String, override val age: Int) extends Cat1(name, age)
abstract class Cat2(val name: String, val age: Int)
class Tabby2(name0: String, age0: Int) extends Cat2(name0, age0)
2,15c2,3
< public class test.Tabby1 extends test.Cat1 {
< public java.lang.String name();
< Code:
< 0: aload_0
< 1: invokespecial #12 // Method test/Cat1.name:()Ljava/lang/String;
< 4: areturn
<
< public int age();
< Code:
< 0: aload_0
< 1: invokespecial #18 // Method test/Cat1.age:()I
< 4: ireturn
<
< public test.Tabby1(java.lang.String, int);
---
> public class test.Tabby2 extends test.Cat2 {
> public test.Tabby2(java.lang.String, int);
20c8
< 3: invokespecial #22 // Method test/Cat1."<init>":(Ljava/lang/String;I)V
---
> 3: invokespecial #12 // Method test/Cat2."<init>":(Ljava/lang/String;I)V
Compiled from "test.scala"
public abstract class test.Cat1 {
private final java.lang.String name;
private final int age;
public java.lang.String name();
Code:
0: aload_0
1: getfield #15 // Field name:Ljava/lang/String;
4: areturn
public int age();
Code:
0: aload_0
1: getfield #20 // Field age:I
4: ireturn
public test.Cat1(java.lang.String, int);
Code:
0: aload_0
1: aload_1
2: putfield #15 // Field name:Ljava/lang/String;
5: aload_0
6: iload_2
7: putfield #20 // Field age:I
10: aload_0
11: invokespecial #25 // Method java/lang/Object."<init>":()V
14: return
}
Compiled from "test.scala"
public abstract class test.Cat2 {
private final java.lang.String name;
private final int age;
public java.lang.String name();
Code:
0: aload_0
1: getfield #15 // Field name:Ljava/lang/String;
4: areturn
public int age();
Code:
0: aload_0
1: getfield #20 // Field age:I
4: ireturn
public test.Cat2(java.lang.String, int);
Code:
0: aload_0
1: aload_1
2: putfield #15 // Field name:Ljava/lang/String;
5: aload_0
6: iload_2
7: putfield #20 // Field age:I
10: aload_0
11: invokespecial #25 // Method java/lang/Object."<init>":()V
14: return
}
Compiled from "test.scala"
public class test.Tabby1 extends test.Cat1 {
public java.lang.String name();
Code:
0: aload_0
1: invokespecial #12 // Method test/Cat1.name:()Ljava/lang/String;
4: areturn
public int age();
Code:
0: aload_0
1: invokespecial #18 // Method test/Cat1.age:()I
4: ireturn
public test.Tabby1(java.lang.String, int);
Code:
0: aload_0
1: aload_1
2: iload_2
3: invokespecial #22 // Method test/Cat1."<init>":(Ljava/lang/String;I)V
6: return
}
Compiled from "test.scala"
public class test.Tabby2 extends test.Cat2 {
public test.Tabby2(java.lang.String, int);
Code:
0: aload_0
1: aload_1
2: iload_2
3: invokespecial #12 // Method test/Cat2."<init>":(Ljava/lang/String;I)V
6: return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment