Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Errr..



I agree that you shouldn't use an instance to invoke statics. But, I've noticed that some newbies stumble on this and become very confused about the roles of static vs. instance methods. And this is why some of the compilers issue a warning, because it's likely the programmer either made an error, or doesn't really understand the concepts.

Don

At 8:24 AM -0800 1/14/06, Bill Stackhouse wrote:
Long x = new Long(5);
String s;
s = x.toString(3);
s = Long.toString(3);

As you suggest, lines 3 and 4 are equivalent, BUT some Java compilers will produce a warning on line 3 indicating that line 4 is the preferred way of writing it. Personally I agree and no longer ever reference a static function without using only the Class name.

Bill

At 9:50 AM -0600 1/14/06, Don Bate wrote:
A static method can be invoked from anywhere the class is visible. If the class is not explicitly specified, then it searches the enclosing scopes looking for a suitable match. Instance method require an object instance to invoke including an implicit 'this'. BTW, you _can_ invoke a static using an object instance, the class used is the class of the instance.

Don Bate
At 9:32 PM -0600 1/13/06, Michael Hall wrote:
On Jan 13, 2006, at 9:13 PM, Matt wrote:

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


--
Don Bate               | Specializing in Consulting and Mentoring in
Bate Consulting, Inc   | Object-Oriented Technologies,
                       | Software Architecture, and Software Process
(972) 618-0208 voice
(972) 618-0216 fax
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Re: Java Swing and Quartz (From: Brian Foster <email@hidden>)
 >Errr.. (From: Bob Irving <email@hidden>)
 >Re: Errr.. (From: Michael Hall <email@hidden>)
 >Re: Errr.. (From: "Matt" <email@hidden>)
 >Re: Errr.. (From: Michael Hall <email@hidden>)
 >Re: Errr.. (From: "Matt" <email@hidden>)
 >Re: Errr.. (From: Michael Hall <email@hidden>)
 >Re: Errr.. (From: Don Bate <email@hidden>)
 >Re: Errr.. (From: Bill Stackhouse <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.