Hacker News new | past | comments | ask | show | jobs | submit login

The Java code ends up being different in subtle ways. Exemplified by this:

  static int x[] = new int[1];

  public static void main1(String[] args) {
    x[1] = grow() ? 10 : 20; //array index out of bounds!
  }

  public static void main2(String[] args) {
    if (grow()) {
      x[1] = 10;
    } else {
      x[1] = 20;
    }
    //no exceptions thrown
  }

  private static boolean grow() {
    x = new int[2];
    return true;
  }



Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: