I'm a little new to this, so sorry if it may seem a naive question. Let's say I have Java class as follows:
public class A {
private final regex = "folder1/folder2/folder3/.*";
private Pattern pattern;
A(...) {
this.pattern = Pattern.Compile(regex)
}
public func1(String str){
if (...){
Matcher m = pattern.matcher(str)
}
}
}
now I'm trying to extend the class A with scala so I can override the regex field and therefore the pattern field following with it.
class B(...) extends A(...){
}
But I'm not sure how to override the regex to be regex = "folder4/.*" for class B
You could pass it into a protected constructor:
Or just declare each as a constant and use an overrideable method to read them: