Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30757
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: java referencing question |
| Date | 2015-01-20 10:03 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <m9lqrr$6lp$1@dont-email.me> (permalink) |
| References | <37e63a38-a2ec-452d-81c3-da09d5999f89@googlegroups.com> |
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