🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17965

Re: How can I assign an Object reference to this in a constructor?

#17965
From: Brian Lauridsen
Date: Tue, 08 Sep 1998 00:00
38 lines
1917 bytes
Hamish McNeish wrote:

> OK here's the plan,
>
> I want to use my constructor to construct a new Object if one does not
> exist otherwise I want to return a reference to an Object that matches
> the Objects criteria.
>
> Can I do this in a constructor? If so how?

No. Not in the constructor.
To do what  you plan to do, check out how JBuilders data modules work.

The basic strategy is to put in your class (MyClass) a static instance of
MyClass, and a static method MyClass gimmeMyClass(), which
returns or initializes the static instance as needed. Then use gimmeMyClass()
to get an (the) instance of the object, not the constructor.

>
> I tried to assign this to the object but my assignment is ignored
> Extent t = this;
> t = theObject;

It looks like you are trying to do pointer assignments.
Forget those nasty C-habits and join the object-oriented world of Java :-)

Extent t = this;
   // t now references the same object as this
t = anotherObject;
  // t now references anotherObject, and has forgotten everything it ever
  // knew about "this" ,
  // so anotherObject and "this" have nothing to do with each other.

>
> however this <> theObject( )
>
> I'm guessing I can't do this in a Constructor, but I'm hoping someone
> can tell me otherwise.
Technical Details
Message-ID: <35F532F3.E41E0C18@yp.aas.dk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <35F4AE5D.2990AADF@sol.otago.ac.nz>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,db7ece1bb334c6e2
X-Google-Attributes: gidf74b3,public
From: Brian Lauridsen <lind@yp.aas.dk>
Subject: Re: How can I assign an Object reference to this in a constructor?
Date: 1998/09/08
Message-ID: <35F532F3.E41E0C18@yp.aas.dk>
X-Deja-AN: 389027242
Content-Transfer-Encoding: 7bit
References: <35F4AE5D.2990AADF@sol.otago.ac.nz>
To: Hamish McNeish <hamcneish@sol.otago.ac.nz>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language