Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30757
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Jeff Higgins <jeff@invalid.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: java referencing question |
| Date | Tue, 20 Jan 2015 10:03:12 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 43 |
| Message-ID | <m9lqrr$6lp$1@dont-email.me> (permalink) |
| References | <37e63a38-a2ec-452d-81c3-da09d5999f89@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Tue, 20 Jan 2015 15:05:31 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="c50a9e5d554cfaba13eda1c71e805135"; logging-data="6841"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187gNuCMmFctS7Rty0qINrfSVsuwWKNlAU=" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0 |
| In-Reply-To | <37e63a38-a2ec-452d-81c3-da09d5999f89@googlegroups.com> |
| Cancel-Lock | sha1:eRgpU/G2PaFywcYBi4tkuQkK5d8= |
| Xref | csiph.com comp.lang.java.programmer:30757 |
Show key headers only | View raw
On 01/20/2015 09:17 AM, John wrote:
>
> I ran into a "strange" problem. If I understood the problem correctly, my summary is here:
>
> public class Team {
> private Person teamLeader;
>
> public Team(Person theLeader) {
> teamLeader = theLeader;
> }
>
> public void doIt() {
> teamLeader.speak();
> ...
> }
>
> }
>
>
> public class Demo {
> public static void main(String[] args) {
> Person leader = null;
> Team dreamTeam = new Team(leader); //teamLeader inside dreamTeam is referencing an object which is also referenced by 'leader'. Right now, the object is null
>
> leader = new Person(); //the object being referenced by leader is a good object now. So I thought teamLeader inside dreamTeam is referencing this good object too, since the two are referencing the same object
> dreamTeam.doIt(); //crashes at teamLeader.speak() due to teamLeader is null -- I don't understand it. Please help.
> }
> }
>
> The design is not good. I will change the design. Here I am puzzled by what I saw. Thank you.
>
4.3 Reference Types and Values
There are three kinds of reference types: class types (§8), interface
types (§9), and array types (§10). Reference types may be parameterized
(§4.5) with type arguments (§4.4).
4.3.1 Objects
An object is a class instance or an array.
The reference values (often just references) are pointers to these
objects, and a special null reference, which refers to no object.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
java referencing question John <xsli2@yahoo.com> - 2015-01-20 06:17 -0800 Re: java referencing question Jeff Higgins <jeff@invalid.invalid> - 2015-01-20 10:03 -0500 Re: java referencing question Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-01-20 10:23 -0500
csiph-web