Re: log4j methods: instance or class?
Charles T. Smith wrote:
On Fri, 22 Jun 2007 09:56:29 -0400, Lew wrote:
Lew wrote:
Charles T. Smith wrote:
If a thing is a class, then it is knowable inside (and outside) all
instances. The same (roughly?) is true with statics.
If a thing is an instance, then it is knowable only within the instance
that defines it. The same (roughly?) is true with non-statics.
If a thing is only meaningful as an instance (because of its dynamic
nature) then would it be an error to assign it to a static variable,
which makes it available to other instances?
I was greatly surprised that java would let me assign the logger to
either a static or a non-static variable.
why? You can assign references to static members to an instance member.
Furthermore, the result of "Logger.getLogger( something )" is neither
static nor non-static.
Wow. That makes it really hard to understand. For example, the JNI spec
says about GetFieldID() (to take the one that's currently sitting in my
browser):
Returns the field ID for an instance (nonstatic) field of a class.
The field is specified by its name and signature...
So, the results of methods can be static, nonstatic, or something else
altogther. Tri-state, so to speak.
No. Results of methods can never be static or non-static. Those are
attributes of class member identifiers, not objects.
The result of a method is a value, either void, a primitive or an object.
These are runtime results, not members of a class, so the keyword "static" is
not relevant. "static" is an attribute of class members, of which there are
three kinds: class definition, variable or method. The return result of a
method is not a member, but might be assigned to a member.
Let me say this again: The result of a method is neither static nor non-static.
The method itself might be static or not. The difference is how you invoke
the method, not what the result is. To invoke a method, you must refer to its
owner, which is either a class for static methods, or an object for instance
methods. It is the method that has the attribute, not the result of it.
You might then assign the result to another variable. Whether that variable
is static or not is a question for the method making the call, but has no
bearing on the reference that the variable will hold.
Really, read up on the meaning of "static".
<http://java.sun.com/docs/books/tutorial/java/javaOO/classvars.html>
I expect experience will clear it up for me.
Not without study it won't.
--
Lew