I'm currently trying to import and use a class in Matlab 2015a that uses the Java Builder pattern and I can't seem to figure out how to instantiate an instance of the object. I can get the classes in my jar file imported into Matlab, but since the outer object has no constructor, I can't figure out how to instantiate the outer class in order to access the inner builder class and build the entire object. Does anyone have any insight into how I can instantiate and build the class in Matlab?
Below is my class setup.
package testJavaBuilder;
public class NutritionalFacts {
private int sodium;
private int fat;
private int carbo;
public static class Builder {
private int sodium;
private int fat;
private int carbo;
public Builder(int s) {
this.sodium = s;
}
public Builder fat(int f) {
this.fat = f;
return this;
}
public Builder carbo(int c) {
this.carbo = c;
return this;
}
public NutritionalFacts build() {
return new NutritionalFacts(this);
}
}
private NutritionalFacts(Builder b) {
this.sodium = b.sodium;
this.fat = b.fat;
this.carbo = b.carbo;
}
}
Aucun commentaire:
Enregistrer un commentaire