Hello, The code you provided works well.
But still, I insist, it has nothing to do with how to solve the problem of how one can overload methods with same name, same arity, but different types in the signature. You only demonstrated that clojure handles well the dispatching of method calls based on dynamic reflection on the types of the arguments, even in the case of an automatically generated method such as helloSuper. -- Laurent 2009/2/13 Craig McDaniel <[email protected]> > > I guess I don't understand. In the Clojure code below, the double > arity method does in fact override all three of the methods from the > superclass (two of which have the same name and same arity). Isn't > that what you're looking for? Try it out. > > |-- build.xml > |-- go.clj > |-- src > | `-- expmeth > | |-- ClassA.java > | `-- TestMe.clj > > $ cat src/expmeth/ClassA.java > package expmeth; > > public class ClassA { > public void hello() { > System.err.println("hello from Java!"); > } > public void hello(int x) { > System.err.println("hello from Java. int: " + x); > } > public void hello(String x) { > System.err.println("hello from Java. string: " + x); > } > } > > $ cat src/expmeth/TestMe.clj > (ns expmeth.TestMe > (:gen-class > :extends expmeth.ClassA > :exposes-methods {hello helloSuper})) > > (defn -hello > ([this] > (.helloSuper this) > (println "hello from clojure!")) > ([this x] > (.helloSuper this x) > (println "hello from clojure..." x))) > > $ cat go.clj > (import '(expmeth TestMe)) > (.hello (TestMe.)) > (.hello (TestMe.) 7) > (.hello (TestMe.) "woo") > > $ cat build.xml > <project name="expmeth" default="jar" basedir="."> > <property name="src.home" location="src"/> > <property name="build.home" location="build"/> > <property name="jarfile" location="expmeth.jar"/> > > <available property="hasclojure" file="${clojure.jar}"/> > > <path id="compile.classpath"> > </path> > > <target name="init"> > <mkdir dir="${build.home}"/> > </target> > > <target name="compile" depends="init"> > <javac srcdir="${src.home}" destdir="${build.home}" debug="on" > includes="**/*.java" deprecation="on" target="1.5" > source="1.5"> > <classpath refid="compile.classpath"/> > <compilerarg line="-Xlint:-path"/> > </javac> > </target> > > <target name="compile-clojure" depends="compile"> > <java classname="clojure.lang.Compile"> > <classpath> > <pathelement location="${build.home}"/> > <pathelement location="${src.home}"/> > <path location="${clojure.jar}"/> > </classpath> > <sysproperty key="clojure.compile.path" value="${build.home}"/> > <arg value="expmeth.TestMe"/> > </java> > </target> > > <target name="jar" depends="compile-clojure"> > <jar jarfile="${jarfile}"> > <fileset dir="${src.home}" includes="**/*.clj"/> > <fileset dir="${build.home}" includes="**/*.class"/> > </jar> > </target> > > <target name="clean" description="cleanup"> > <delete dir="${build.home}"/> > <delete file="${jarfile}"/> > </target> > > </project> > > $ ant > > $ java -cp build:/home/kreg/src/clojure/clojure.jar clojure.main > go.clj > hello from Java! > hello from clojure! > hello from Java. int: 7 > hello from clojure... 7 > hello from Java. string: woo > hello from clojure... woo > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
