File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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 !!!
I agree. Here's the link:
subject: Static method
jQuery in Action, 3rd edition