简体   繁体   English

如何从 Java 应用程序中的另一个类访问在实用程序类中声明的公共最终静态列表?

[英]How can I access to a public final static list declared into an utility class from another class in a Java application?

I have the following doubt.我有以下疑问。 Into a Java application I have an utility class like this:在 Java 应用程序中,我有一个像这样的实用程序类:

public class CodUtility {

    /* TIPOLOGIA PROGETTO */
    public static final String CODICE_PROGETTO_WIFI = "W";
    public static final String CODICE_PROGETTO_LIM = "L";
    public static final String CODICE_PROGETTO_ALTRO = "A";
    public static final String CODICE_PROGETTO_CLASSI20 = "2";
    public static final String CODICE_PROGETTO_SCUOLA20 = "S";
    public static final String CODICE_PROGETTO_CSD = "C";

    public static final LinkedHashMap<String, String> hashMapDescrizioneTipologiaProgetto = new LinkedHashMap<String, String>();
    static {
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_WIFI, "WIFI");
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_LIM, "LIM");
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_ALTRO, "Altro");
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_CLASSI20, "Classi 2.0");
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_SCUOLA20, "Scuola 2.0");
        hashMapDescrizioneTipologiaProgetto.put(CODICE_PROGETTO_CSD, "CSD");
    }

    public static final List<String> listaCodiciTipologiaProgetto = new ArrayList<>(hashMapDescrizioneTipologiaProgetto.keySet());
    /* FINE TIPOLOGIA PROGETTO */
}

This class define this public final static list:这个类定义了这个公共最终静态列表:

public static final List<String> listaCodiciTipologiaProgetto = new ArrayList<>(hashMapDescrizioneTipologiaProgetto.keySet());

Now my doubt is: ho can I retrieve it from another class.现在我的疑问是:我可以从另一个类中检索它吗? I need to retrieve this list from another class and access to it.我需要从另一个类中检索此列表并访问它。

How can I do this operation?我怎样才能做这个手术?

Are you just trying to get the list from another object?你只是想从另一个对象中获取列表吗?

CodUtility.listaCodiciTipologiaProgetto; Will return the list.将返回列表。

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

相关问题 如何从 Scala 访问 Java 类中的公共静态最终成员? - How to access a public static final member in a Java class from Scala? 我如何从另一个包中实例化Java内部的public static final类 - How can I instantiate a inner public static final class in java from a different package 我可以在Java中嵌套的公共静态抽象类中读取公共静态最终字段吗 - can I read public static final field inside a nested public static abstract class in Java 如何从ColdFusion访问Java类的公共静态成员? - How can I access a public static member of a Java class from ColdFusion? 如何在java中设置公共静态最终类实例的值 - how to set the values for a public static final class instance in java 导入的java类中的public static final变量 - public static final variable in an imported java class 如何从JSP访问Java类中的公共静态变量 - How to access public static variable in a Java class from a JSP 从最终类(实用程序类)模拟私有静态方法 - Mocking private static method from a final class (utility class) 修改最终公共类Java中的最终静态变量 - Modifying final static variable within final public class Java 我怎样才能在另一个班级访问这个列表? - How can I access this list in another class?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM