new a class. You can overload constructors with different parameters — Apex picks the matching signature.Which constructor runs?
new Service("acme")
public class Service {
public Service() {
// default
}
public Service(String tenant) {
this();
}
public Service(String tenant, Boolean strict) {
this(tenant);
}
}Use constructors to establish invariants — if bad input, throw a clear exception early.