I have a class called Scraper with a static inner class Builder, and also a non-static inner class called StringPair, I'm trying to get one of the builder methods to construct a new StringPair(a,b) and add it to an ArrayList<StringPair>, however it doesn't compile, the compiler says Error: non-static variable this cannot be referenced from a static context and specifically highlights the new StringPair(a,b) as the source of the problem.
I don't understand what's wrong here, any help would be appreciated!
class Scraper {
private final ArrayList<StringPair> stringPairs;
Scraper(Builder builder) {
stringPairs = builder.builderStringPairs;
}
public static class Builder {
private static ArrayList<StringPair> builderStringPairs = new ArrayList<StringPair>();
public Builder addStringPairs(String a, String b) {
builderStringPairs.add(new StringPair(a, b));
return this;
}
public Scraper build() {
return new Scraper(this);
}
}
class StringPair {
String a,b;
StringPair(String a, String b) {
this.a = a;
this.b = b;
}
String getA() {
return a;
}
String getB() {
return b;
}
}
}