Skip to main content
Post Reopened by CommunityBot, Alexei - check Codidact, slfan, Unheilig, ρяσѕρєя K
added 198 characters in body
Source Link
user235273
user235273

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: as the linked example I tried

 (ns subclass.core (:gen-class :extends Baseclass :exposes-methods {greet pgreet}) (:import Baseclass)) (defn greet [] (.pgreet (Baseclass.))) (defn -main [& args]) 

But when I call (greet) I am getting the error

IllegalArgumentException No matching field found: pgreet for class Baseclass clojure.lang.Reflector.getInstanceField (Reflector.java:271) 

Is this the right way to call the super class method?

Update: Got it. We create a different method which will intern call the base class method. https://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/Java_Interaction#genclass
NB: that's not what the linked answer says.

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: as the linked example I tried

 (ns subclass.core (:gen-class :extends Baseclass :exposes-methods {greet pgreet}) (:import Baseclass)) (defn greet [] (.pgreet (Baseclass.))) (defn -main [& args]) 

But when I call (greet) I am getting the error

IllegalArgumentException No matching field found: pgreet for class Baseclass clojure.lang.Reflector.getInstanceField (Reflector.java:271) 

Is this the right way to call the super class method?

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: as the linked example I tried

 (ns subclass.core (:gen-class :extends Baseclass :exposes-methods {greet pgreet}) (:import Baseclass)) (defn greet [] (.pgreet (Baseclass.))) (defn -main [& args]) 

But when I call (greet) I am getting the error

IllegalArgumentException No matching field found: pgreet for class Baseclass clojure.lang.Reflector.getInstanceField (Reflector.java:271) 

Is this the right way to call the super class method?

Update: Got it. We create a different method which will intern call the base class method. https://en.wikibooks.org/wiki/Clojure_Programming/Examples/API_Examples/Java_Interaction#genclass
NB: that's not what the linked answer says.

added 535 characters in body
Source Link
user235273
user235273

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: as the linked example I tried

 (ns subclass.core (:gen-class :extends Baseclass :exposes-methods {greet pgreet}) (:import Baseclass)) (defn greet [] (.pgreet (Baseclass.))) (defn -main [& args]) 

But when I call (greet) I am getting the error

IllegalArgumentException No matching field found: pgreet for class Baseclass clojure.lang.Reflector.getInstanceField (Reflector.java:271) 

Is this the right way to call the super class method?

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass)) (defn greet [] "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: as the linked example I tried

 (ns subclass.core (:gen-class :extends Baseclass :exposes-methods {greet pgreet}) (:import Baseclass)) (defn greet [] (.pgreet (Baseclass.))) (defn -main [& args]) 

But when I call (greet) I am getting the error

IllegalArgumentException No matching field found: pgreet for class Baseclass clojure.lang.Reflector.getInstanceField (Reflector.java:271) 

Is this the right way to call the super class method?

Post Closed as "Duplicate" by coredump, amalloy clojure
revert
Source Link
user235273
user235273

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass))  (defn greet []    :exposed-methods {greet baseGreet})) ;added"Hello exposedfrom method (defncore") greet [this] ; how to call (super.baseGreet this)greet()? (defn -main [& args] (greet)) ;how to pass this? 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: updated sample to reflect the linked answer.

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass :exposed-methods {greet baseGreet})) ;added exposed method (defn greet [this]  (.baseGreet this)) (defn -main [& args] (greet)) ;how to pass this? 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 

Edit: updated sample to reflect the linked answer.

I want to call a method in the super class from Clojure. I am extending a Java class using :gen-class.

(ns subclass.core (:gen-class :extends Baseclass))  (defn greet []    "Hello from core") ; how to call super.greet()? (defn -main [& args] (greet)) 

Java Baseclass

public class Baseclass { public String greet() { return "Hello from Baseclass"; } } 
added 112 characters in body
Source Link
user235273
user235273
Loading
Source Link
user235273
user235273
Loading