Invariant not obeyed for private constructor
Reported by Thomas Han | May 16th, 2011 @ 10:16 AM
@Invariant({
g != null
}) class G {
String g
private G(String g) {
this.g = g
}
static G of(String g) {
return new G(g)
}
}
If we construct the G object with the static method the invariant is not obeyed.
Comments and changes to this ticket
-
me (at andresteingress) May 18th, 2011 @ 11:15 AM
- State changed from new to hold
- Assigned user set to me (at andresteingress)
this behavior is ideational to allow GContracts to be used in frameworks like Hibernate etal. that make use of private/protected constructors to create uninitialized objects. therefore private constructors are not supported by now.
-
Thomas Han May 18th, 2011 @ 11:29 AM
There are other scenarios where private constructors are valid.
Private constructors might be used by static factory methods.
Ideally you would want to centralised the contract on the constructors not on the static factory method.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
core module