[Prev][Next][Index][Thread]

Re: Subject reduction fails in Java



Haruo, Benli, Dave,

This is the least of your problems.  Reduction, in the sense
you define it, can easily change the meaning of a program,
thanks to Java's notion of overloading.

Original program prints "true".

  class Counterexample {
    static boolean overloaded (Object x) { return true; }
    static int overloaded (String s) { return 42; }
    static void m (Object x) { System.out.println(overloaded(x)); }
    public static void main (String[] args) {
      m("hello");
    }
  }

Reduced program prints "42".

  class Counterexample {
    static boolean overloaded (Object x) { return true; }
    static int overloaded (String s) { return 42; }
    static void m (Object x) { System.out.println(overloaded(x)); }
    public static void main (String[] args) {
      System.out.println(overloaded("hello"));
    }
  }

Yours,  -- P

-----------------------------------------------------------------------
Philip Wadler                             wadler@research.bell-labs.com
Bell Labs, Lucent Technologies      http://www.cs.bell-labs.com/~wadler
600 Mountain Ave, room 2T-402                   office: +1 908 582 4004
Murray Hill, NJ 07974-0636                         fax: +1 908 582 5857
USA                                               home: +1 908 626 9252
-----------------------------------------------------------------------