简体   繁体   English

如何在Java的同一包中获取由一个类中的一个函数生成的数据在另一个类中

[英]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. 现在我当前的项目中有一个包含2个Java类的包。 One of them pull data from a table and rearrange into a Map . 其中一个从表中提取数据,然后重新排列到Map The other class does the checking work in which it need access this Map frequently. 另一个类执行需要经常访问此Map的检查工作。 Obviously, I don't want to generate this Map every time the checking class called. 显然,我不想每次检查类都调用时生成此Map What is the easiest and most efficient way for me to store that Map making my checking class work faster. 对我而言,最简单,最有效的方法就是存储该Map从而使检查类的工作更快。 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. 为了清楚起见,检查类扩展了火花UDF1的抽象类。 So it will work as a UDF on spark. 因此,它将作为火花上的UDF使用。 No main function in both classes, THx. 这两个类别都没有主要功能,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;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java-如何获取从一个类中的方法生成到另一个类中的变量? - Java - How do I get a variable generated from within a method in one class to another class? 如何从一个类到同一包的另一个类访问一个变量 - How to access one variable from one class to another of the same package 我可以在同一程序包下的另一个类中调用一个类的静态方法吗? - Can I call a static method of one class in another class under same package? 如何在Java中同一包中的不同文件上从一个类访问另一个类的变量 - How to access a variable from one class into another class on different files in same package in java 如何将数据从一个包中的类发​​送到另一个包中的类? - How do I send data from a class in one package to a class in another package? 如何从一个 class 中的扫描仪获取用户输入,然后将其应用于同一 package 中的另一个 class? - How do I take an user input from Scanner in one class and then apply it to another class in the same package? 为什么一类相同的包不能访问另一类? - why one class of same package can't access another? 如何获取另一个文件中一个类中已经存在的对象的数据,并将其用于Java中另一个文件中的另一个类? - How to get data of an object that already existed in one class in another file and use it to another class in another file in Java? 如何在Java中将变量从一类传递到另一类? - How can I pass variables from one class to another in Java? 我可以在一个 java 包中定义多个公共类吗 - can i define more than one public class in a java package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM