This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Using this and static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using this and static" Watch "Using this and static" New topic
Author

Using this and static

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 743
Hi, small dilemma here...

If I have the class below


Obviously that won't work since you can't use 'this' with static,
so if the parameter being passed in is the same as the class variable,
how can we distinguish them?

You could pass in a different variable (say m), but this seems like
running away from the problem.
Is the standard way to just do ABC.n=n; ???

Thanks
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

You can use the usual method of assigning a class (static) variable, by qualifying the class variable with the class name:



Kaydell
[ May 25, 2007: Message edited by: Kaydell Leavitt ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using this and static
 
Similar Threads
ints and arrays........
David Smalley
compile time constant expression
encapsulating static variables
How to check a datatype of a variable