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.

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();
  • 1
    Literally just did this right as your answer came in. After I typed out my problem I saw it more clearly :P – Xtremefaith Feb 24 '16 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 Feb 24 '16 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.