• Post Reply Bookmark Topic Watch Topic
  • New Topic

Type of reference when referring a static?  RSS feed

 
Max Fan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java doc mentions reference to refer objects, arrays. But how about static? When I refer a static of a class, what type of reference is used?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need a referenec to refer to a static class member. You just use the class name.
e.g. If dosomething is a static method in class StaticTest, you just type
 
Max Fan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:You don't need a referenec to refer to a static class member. You just use the class name.
e.g. If dosomething is a static method in class StaticTest, you just type


That's what I'm asking. The name of this class is actually a "reference", right? Compared with object reference, it could be relatively static in terms of memory location. Unfortunately I even forgot the reason I raise this question. But if you want to shed lights, appreciate a lot.
 
Paul Clapham
Sheriff
Posts: 22829
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it isn't. Only variables can contain references. For example if you have this code:

then a Date object is created, and the "now" variable is made to contain a reference to that object.

It isn't correct to use the word "reference" to mean a method call. In Java it only means a reference to an object.

And that means that questions about "static" are irrelevant, since there is no such thing as a "static object". There are certainly static variables, which can certainly contain references to objects, but that doesn't make those objects "static". And since you can't have a reference to a variable (only references to objects exist), it wouldn't make sense to talk about references to a static variable.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!