Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Invariant not obeyed for private constructor

#24

@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.

Reported by Thomas Han · May 16th, 2011 @ 10:16 AM

State: hold
Milestone: none

Activity

  1. me (at andresteingress)
    me (at andresteingress)
    • 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.

    May 18th, 2011 @ 11:15 AM

  2. Thomas Han
    Thomas Han

    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.

    May 18th, 2011 @ 11:29 AM

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.