Is there any way I can trigger class constructor automatically while extending from the class?
I have a class TestSet.java
public class TestSet {
public TestSet(String name) {
Logger.msg("Test set: " + name);
}
}
And I would like for the constructor to trigger every time that I extend from this class.
It seems that I need to call the constructor "manually" with:
public class TC1SendAnEmail extends TestSet{
//I have to type this every single time again and again...
//---------------------------------------------------------
public TC1SendAnEmail(String name) {
super(name);
}
//---------------------------------------------------------
public void run() {
new EmailLogin().run();
...
}
}
Which I would like to avoid. (Because I will be creating possibly hundreds/thousands of those extended classes.)
From what I have managed to research, I guess that this function is not implemented in Java. But it just seems weird that I would have to "copy-paste" the constructor again, again and again...
Maybe there is another solution that I dont see? (Maybe without even using the constructor to "do something every time an instance of a class that extends my TestSet class is created".)
EDIT: Yes, I can see why you think that creating hundreds/thousands of subclasses is wrong. I am creating a big automation project. Every class of this type will be a "test". And there will be thousands of tests...
EDIT#2: The point of this question was that I needed to trigger the superclass constructor every time I extend from it. My mistake was adding parameter to the superclass constructor. If you don´t add a parameter to the constructor, then it is triggered automatically while extending.