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....
posted 15 years ago
Hi, 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 !!!