0

I have a problem today because I do not know how to call a java class which extends a sublass. I know there is the $ sign for nested class but here I'm lost.

To be more clear, here are the classes :

Abstract class :

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/fitting/AbstractCurveFitter.html

Subclass :

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/fitting/SimpleCurveFitter.html

To be honest, I forgot a lot of thing about java but I see there is no constructor for the subclass. The problem is that I must use the sublass.

Here is the code

(defn apache-logistic-reg [data x0 lamb] (let [f (Logistic$Parametric.) start (def-start x0 lamb) fitter (.create SimpleCurveFitter. f start) points (double-array (extract-points data))] (.fit fitter points))) 

The problem is that I cannot call SimpleCurveFitter. because it has no constructor. And AbstractCurveFitter has no .create, plus if I remember it well abstract classes cannot be cast.

And if I remember well, the constructor of SimpleCurveFitter would have the name of its abstract class but maybe I'm wrong.

How can I do ?

Thanks you

1 Answer 1

2

You don't need to call a constructor in SimpleCurveFitter, because it provides the static method create to get an instance for you (which you're already trying to use). Just make a static method call to that method to get an instance:

(.create SimpleCurveFitter f start) ;; No '.' after SimpleCurveFitter (. SimpleCurveFitter create f start) ;; Alternate syntax (SimpleCurveFitter/create f start) ;; Most common syntax (pointed out by amalloy) 
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot, finally it was "simple" like String and so on, I imagined harder manipulations !
The third syntax here is by far the most typical one to use for calling static methods.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.