Re: Python syntax in Lisp and Scheme

From: Pascal Costanza (costanza_at_web.de)
Date: 10/08/03


Date: Wed, 08 Oct 2003 23:50:41 +0200

Christopher C. Stacy wrote:

> JAVA has multi-methods with non-congruent arglist.
> (It doesn't have multiple inheritence, but that doesn't
> matter to dynamic type dispatching, except maybe in how
> you implement searching your handler tables.) In JAVA,
> the correspondance of the "signature" of the function call
> and the method definition are what's important;
> and there are no restricting "generic functions".
>
> public class RandomAccessFile extends Object,implements DataOutput {
> public void write(byte[] b) throws IOException;
> public void write(byte[] b, int off, int len) throws IOException;
> ...
> }

Maybe this is just a terminological issue, but in my book these are not
multi-methods. In Java, methods with the same name but different
signatures are selected at compile time, and this is rather like having
the parameter types as part of the method name.

This can lead to subtle bugs. Here is an example in Java:

public class test {

     static void m(Object o) {
       System.out.println("m/Object");
     }

     static void m(String s) {
       System.out.println("m/String");
     }

     static void n(Object o) {
       m(o);
     }

     public static void main(String[] args) {
       n("test");
     }

}

This prints "m/Object", instead of "m/String" as you might expect. (This
is one of the reasons why the Visitor pattern is relatively tedious to
implement in Java.)

Pascal



Relevant Pages

  • Re: Determining the Main Class
    ... public class Main {public static void method ... In the stack trace above, ... searching the ThreadGroups, and also via Thread.getAllStacktraces. ... you'd have to know the command the java executable was started with to ...
    (comp.lang.java.programmer)
  • Re: Python syntax in Lisp and Scheme
    ... > matter to dynamic type dispatching, ... > you implement searching your handler tables.) ... > public class RandomAccessFile extends Object,implements DataOutput { ... In Java, methods with the same name but different ...
    (comp.lang.lisp)
  • Re: returning a pair of iterator.
    ... Java is not C++. ... If you don't trust someone with your ... public int getData() ... public class ValuableObject implements ReadableValuableObject {... ...
    (comp.lang.java.programmer)
  • Re: cast to sub-class or extending instance of super or a.n.other
    ... In java, the set of attributes is defined by the class, which is defined at compile-time; when you have an instance, it's runtime, by which point the class definitions are set in stone. ... public class ThingWithMinimumMessageNumber { ... private int minimumMessageNumber; ... public ThingWithMinimumMessageNumber(OriginalThing thing, int minimumMessageNumber) { ...
    (comp.lang.java.programmer)
  • Re: Beating a Dead Horse: NoClassDefFoundError
    ... > Thread model: posix ... > I've been doing java for a couple of days now, ... > public class hello ... IBM Australia - Tivoli Security Software ...
    (comp.lang.java.programmer)