Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class One {
  2.     private final Object o = new Object();
  3.     private final String s = (String) o;
  4. }
  5. -----
  6. javap -c One:
  7.  
  8. public One();
  9.   Code:
  10.    0:   aload_0
  11.    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
  12.    4:   aload_0
  13.    5:   new     #2; //class java/lang/Object
  14.    8:   dup
  15.    9:   invokespecial   #1; //Method java/lang/Object."<init>":()V
  16.    12:  putfield        #3; //Field o:Ljava/lang/Object;
  17.    15:  aload_0
  18.    16:  aload_0
  19.    17:  getfield        #3; //Field o:Ljava/lang/Object;
  20.    20:  checkcast       #4; //class java/lang/String
  21.    23:  putfield        #5; //Field s:Ljava/lang/String;
  22.    26:  return
  23.  
  24. }
  25.  
  26. ================================
  27.  
  28. public class Two {
  29.     private final Object o = new Object();
  30.     private final String s = String.class.cast(o);
  31. }
  32. -----
  33. javap -c Two:
  34.  
  35. public Two();
  36.   Code:
  37.    0:   aload_0
  38.    1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
  39.    4:   aload_0
  40.    5:   new     #2; //class java/lang/Object
  41.    8:   dup
  42.    9:   invokespecial   #1; //Method java/lang/Object."<init>":()V
  43.    12:  putfield        #3; //Field o:Ljava/lang/Object;
  44.    15:  aload_0
  45.    16:  ldc_w   #4; //class java/lang/String
  46.    19:  aload_0
  47.    20:  getfield        #3; //Field o:Ljava/lang/Object;
  48.    23:  invokevirtual   #5; //Method java/lang/Class.cast:(Ljava/lang/Object;)Ljava/lang/Object;
  49.    26:  checkcast       #4; //class java/lang/String
  50.    29:  putfield        #6; //Field s:Ljava/lang/String;
  51.    32:  return
  52.  
  53. }