Mac
Mac

Reputation: 1495

Constructor publishing itself then throwing exception

In following code snippet, will published object be garbage collected ? Is there any chance that published will stay around as a half constructed object ?

final class Publisher
{
    public static volatile Publisher published;
    public Publisher()
    {
        published = this;
        throw new RuntimeException("Construction not allowed.");
    }
}

Upvotes: 0

Views: 164

Answers (0)

Related Questions