From: Mike Schilling on
Patricia Shanahan wrote:
> Mike Schilling wrote:
>> Suppose the call to "super()" needn't be the first line of a
>> constructor. Discuss the effect and/or legality of the following
>> code: class MyClass extends YourClass
>> {
>> public MyClass(int i)
>> {
>> if ( i > 0)
>> {
>> super(i);
>> }
>> }
>> ...
>>
>>
>
> The most complete way of dealing with this would be to have two
> concepts, "definitely constructed" and "definitely not constructed"
> that would be calculated in a similar way to "definitely assigned".
>
> At the start of the body of the constructor "definitely constructed"
> is false and "definitely not constructed" is true.
>
> Use of super and this to call another constructor is permitted if, and
> only if, "definitely not constructed" is true.
>
> References that use "this", return and fall through to the end of the
> constructor are permitted if, and only if, "definitely constructed"
> is true.
> Even if neither is true, completion through throw of an exception is
> permitted.
>
> In the example case, at the end of the if statement "definitely
> constructed" is false because of the i >= 0 case. "definitely not
> constructed is false because of the i < 0 case. There can be no more
> super or this calls, and the constructor must complete by throwing an
> exception.
>
> Constructors that follow the current standard would transition to
> "definitely constructed" true and "definitely not constructed" false
> after the first statement of the constructor body.

Good Lord, Patricia, I said "discuss", not "develop the complete theory of"
:-)


From: Eric Sosman on
On 2/11/2010 11:33 AM, Mike Schilling wrote:
> Patricia Shanahan wrote:
>> [... sensible stuff ...]
> Good Lord, Patricia, I said "discuss", not "develop the complete theory of"
> :-)

She's a PhD. That's what PhD's do. Get over it. :-)

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Lew on

Patricia Shanahan wrote:
>>> [... sensible stuff ...]

Mike Schilling wrote:
>> Good Lord, Patricia, I said "discuss", not "develop the complete
>> theory of"
>> :-)

Eric Sosman wrote:
> She's a PhD. That's what PhD's do. Get over it. :-)

And a genius. That's what geniuses do, too.

(No smiley because it's the simple truth.)

--
Lew
From: Tom Anderson on
On Wed, 10 Feb 2010, Mike Schilling wrote:

> Suppose the call to "super()" needn't be the first line of a constructor.
> Discuss the effect and/or legality of the following code:
>
> class MyClass extends YourClass
> {
> public MyClass(int i)
> {
> if ( i > 0)
> {
> super(i);
> }
> }
> ...

A relaxing of the current rule which didn't ban that would be remiss
indeed.

tom

--
As Emiliano Zapata supposedly said, "Better to die on your feet than
live on your knees." And years after he died, Marlon Brando played him
in a movie. So just think, if you unionize, Marlon Brando might play
YOU in a movie. Even though he's dead. -- ChrisV82
From: markspace on
Tom Anderson wrote:
> On Wed, 10 Feb 2010, Mike Schilling wrote:
>
>> Suppose the call to "super()" needn't be the first line of a constructor.
>> Discuss the effect and/or legality of the following code:
>>
>> class MyClass extends YourClass
>> {
>> public MyClass(int i)
>> {
>> if ( i > 0)
>> {
>> super(i);
>> }
>> }
>> ...
>
> A relaxing of the current rule which didn't ban that would be remiss
> indeed.


True, but something like this should be acceptable, imo:

class MyClass extends YourClass
{
public MyClass(int i)
{
if ( i > 0)
{
super(i);
} else
{
super();
}
}
...

Because now the object is definitely constructed and also we've done
something useful that the current JLS doesn't allow us to do.