Search code examples
javascalagetter-setter

How do I access a "getter" of a Java method from a scala method?


I have a Java method that looks something like this:

public class JavaClass{

private static ArrayList<String> stringModel= new ArrayList<String>();

public JavaClass (String name) {
-----------------------------
-----------------------------
     /*Do required operations*/
-----------------------------
-----------------------------

}

public static ArrayList<String> getStringModel() {
    return autosarModel;
}
public static void setStringModel(ArrayList<String> stringModel) {
    JavaClass.stringModel = stringModel;
}

I am trying to access the getStringModel from my scala classthat looks something like this:

 val sm = new JavaClass("Folder1")
 val x = sm.getStringModel

I can seem to use the setStringModel from this scala class, but for some reason I get an error saying:

"value getStringModel" not found.

Can somebody tell me what am I doing wrong here?


Solution

  • The method is static, meaning it's defined on the class rather than an instance of the class.

    You need:

    val model = JavaClass.getStringModel("Folder1")