Results 1 to 11 of 11
Thread: this pointer
- 08-21-2012, 09:11 PM #1
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
- 08-21-2012, 09:14 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: this pointer
bar = bar would have no effectJava Code:class Foo{ private int bar; public Foo(int bar){ this.bar = bar; } }
/edit: Advanced java?
Last edited by eRaaaa; 08-21-2012 at 09:16 PM.
- 08-21-2012, 09:23 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
Re: this pointer
but i can write like
class Foo{
public Foo(int a){
bar = a;
}
}
without using this
- 08-21-2012, 09:41 PM #4
Senior Member
- Join Date
- Oct 2011
- Location
- Sweden
- Posts
- 123
- Rep Power
- 0
Re: this pointer
This refers to the current object. Look into shadow variables, as well as local and instance variables.
- 08-21-2012, 10:14 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
Re: this pointer
@zyril ,can you please tell me, can I have a problem like without This i cant have a solution?
- 08-22-2012, 01:19 AM #6
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
- 08-22-2012, 02:36 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: this pointer
I think so. Which raises the question... why?
Without much thought I'll hazard the guess that you never actually need "this" unless nested classes are involved when it's necessary to disambiguate types rather than methods or variables. (someone will doubtless correct me if I'm wrong).
But the real question is why you would prefer some contrived, verbose, frown inducing, eyebrow raising alternative when "this" would do the job nicely.
- 08-22-2012, 06:39 AM #8
Member
- Join Date
- Aug 2012
- Posts
- 4
- Rep Power
- 0
- 08-22-2012, 07:05 AM #9
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
- 08-22-2012, 09:19 AM #10
- 08-22-2012, 09:40 AM #11
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Similar Threads
-
Null pointer exception
By Domo230 in forum New To JavaReplies: 4Last Post: 02-28-2011, 10:21 AM -
Null pointer exceptio
By grifan526 in forum New To JavaReplies: 0Last Post: 03-05-2010, 02:00 AM -
Null Pointer
By theen3my in forum AWT / SwingReplies: 3Last Post: 10-03-2009, 02:10 PM -
null pointer help
By mayhewj7 in forum New To JavaReplies: 5Last Post: 02-17-2009, 11:51 PM -
A variable pointer
By tapies in forum New To JavaReplies: 13Last Post: 09-12-2008, 10:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks