Skip to content

Instantly share code, notes, and snippets.

@trasa
Created May 25, 2016 23:33
Show Gist options
  • Save trasa/ceac6517d99530a94a70c6337c57bd97 to your computer and use it in GitHub Desktop.
Save trasa/ceac6517d99530a94a70c6337c57bd97 to your computer and use it in GitHub Desktop.
import java.util.*;
public class Initials {
private String foo = null;
private int i = 0;
private Map<String, Integer> map = null;
}
Compiled from "Initials.java"
public class Initials {
public Initials();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: aconst_null
6: putfield #2 // Field foo:Ljava/lang/String;
9: aload_0
10: iconst_0
11: putfield #3 // Field i:I
14: aload_0
15: aconst_null
16: putfield #4 // Field map:Ljava/util/Map;
19: return
}
Compiled from "NotInitials.java"
public class NotInitials {
public NotInitials();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: return
}
import java.util.*;
public class NotInitials {
private String foo;
private int i;
private Map<String, Integer> map;
}
@trasa
Copy link
Author

trasa commented May 25, 2016

Setting the fields to null (or their default) causes the fields to be initialized twice. This isn't the end of the world and is unlikely to break your application (and might even be optimized away when the app starts?) but, still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment