This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static method" Watch "Static method" New topic

Static method

Michael Mendelson
Ranch Hand

Joined: Dec 19, 2000
Posts: 73
I'm a little confused about how to use Static methods. Here's my situation:
I'm creating a class which hold some HashMaps. This is basically a container for an entire data set. There will only be one instance in the app. I would like to create methods in this class to do various operations on the entire dataset.
My intuition is to make the HashMaps static. So far, no problem.
The problem comes when I call a method of one of the objects contained in a HashMap. For example, I would like to make a calculation on all objects in a HashMap. The compiler will not allow me to access non-static methods/variables "from a static context."
Why not? Thanks in advance for your response....
Chris Johns

Joined: Jan 13, 2001
Posts: 15

U have made the objects of the type Hash Map static, However this does not mean that the built in non static methods of the class HashMap can be accessed without the HashMap object i.e for accessing a non static HashMap method, one always requires a HashMap object not a HashMap class variable.
Good Luck !!!
wood burning stoves
subject: Static method
It's not a secret anymore!