I am a junior developer and I am familiar with the theory behind java abstract classes and how they can have constructors to force subclasses to set certain constructor parameters, and how abstract classes themselves cannot be instantiated. However, when looking at some refactored code in my company's test framework I am slightly puzzled.
This abstract class
public abstract class WaitForTestOutcomeThenAssert {
private long maxWait;
public WaitForTestOutcomeThenAssert(long maxWait) {
this.maxWait = maxWait;
}
public void waitForConditionThenAssert() {
...
...
}
protected abstract boolean checkCondition();
}
gets referenced in this class:
public class DbWrapper extends AbstractDB {
@Override
public void assertColumnValueNotNull(final String schema, final String table, final String columnName, final String whereClause) {
new WaitForTestOutcomeThenAssert(this.assertionTemporalTolerance) {
@Override
public boolean checkCondition() {
return getColumnValue(schema, table, columnName, whereClause) != null;
}
}.waitForConditionThenAssert();
}
}
Since we can't instantiate an abstract class, can someone please explain to me exactly what happens and what gets created when we use new keyword in front of an abstract class constructor?