2

I have a wrapper/inner class like so:

public class parameter{

    public String source { get; set; }
    public Integer year { get; set; }
    public String field { get; set; }

    public parameter(String source, Integer year, String field){
        this.source = source;
        this.year = year;
        this.field = field;
    }

}

Now from a method in the base class if I attempt to get one of these attributes like so:

private String getValue(Parameter p){
    String test1 = p.getSource();
    Integer test2 = p.getYear();
    String test3 = p.getField();
}

I the following error:

Error: Method does not exist or incorrect signature

If I attempt to make the attributes static I get reminded that only outer-classes can have static attributes.

1 Answer 1

4

Since source, Year and Field are variable then Just use p.source, p.Year and p.Field

String test1 = p.getSource();
Integer test2 = p.getYear();
String test3 = p.getField();

Instead try

String test1 = p.source;
Integer test2 = p.Year;
String test3 = p.Field;

If you create a method like

public class parameter{

    public String source { get; set; }
    public Integer year { get; set; }
    public String field { get; set; }

    public parameter(String source, Integer year, String field){
        this.source = source;
        this.year = year;
        this.field = field;
    }

    public String getSource(){
      return 'test ';
    }    
}

then use

p.Source();
2
  • 1
    Literally just did this right as your answer came in. After I typed out my problem I saw it more clearly :P Commented Feb 24, 2016 at 8:51
  • It's often like that. If you're passing values in the constructor you can probably switch to private set. @Xtremefaith
    – Adrian Larson
    Commented Feb 24, 2016 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .