T
T
timeofview2017-08-29 14:40:54
Java
timeofview, 2017-08-29 14:40:54

Java. Problem with HashMap, how to use it in non main class?

Can't use object of type HashMap in non-main class. When I create in the main class, everything works, and I can also access the HashMap object in a third-party class when creating an object of the class itself.
Here is an example.
public class Member {
public static void main(String[] args) {
Math m = new Math();
m.hmap.put("A", "B");
// Everything works fine here
}
}
mport java.util.HashMap;
import java.util.Map;
public class Math {
Map hmap = new HashMap<>();
//write here hmap.put("A", "B"); I can no longer.
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question