If I had a HashMap such as in the following, how would I utilize it from another method? In this case, from Main?
public class Scratch {
public static void init() {
WordEnums words = new WordEnums();
List<String> bookList = new ArrayList<String>();
for (WordEnums.Book bookValues : WordEnums.Book.values()) {
bookList.add(bookValues.getDefinition());
}
HashMap<String, Object> wordDefinitions = new HashMap<>();
wordDefinitions.put("book", bookList);
}
public static void main(String[] args) {
List<String> book = (List<String>) wordDefinitions.get("book");
book.stream().forEach(s -> {
System.out.print(" ");
System.out.println(s);
});
}
I've tried moving it outside of init, something along the lines of what I could find here
But upon doing so, I get an error and am unable to access bookList within init.
Thanks
initmethod need to bestatic?initshould bestatic