简体   繁体   中英

How can I get data generated by one function in one class in another class in same package in java

now I have a package in my current project with 2 java classes. One of them pull data from a table and rearrange into a Map . The other class does the checking work in which it need access this Map frequently. Obviously, I don't want to generate this Map every time the checking class called. What is the easiest and most efficient way for me to store that Map making my checking class work faster. I hope to find a way to make that Map global accessible within my package after it is generated. Need advice!

To make it clear, the checking class extend abstract class of a spark UDF1. So it will work as a UDF on spark. No main function in both classes, THx.

If I understood your question correct.. It is like below

public class Loader {

    public static Map<K, V> holder;

    public void loadMap() {
        // Code to populate map goes here
    }
}

and you will be able to access map like

public class Checker {

    public void check() {
        // Acccess map like this Loader.holder;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM