首页 > 解决方案 > 如何从其他类访问arrayLists(可能在其他包中)

问题描述

我需要从其他包中的其他类访问我在 me.tylercreator.FallenSurv 主类中创建的 ArrayList。

我有不同的包,但我需要每个类都能够从一个类访问某些 ArraysList。

我试图将它们声明为 public static ,但是我只能在同一个文件中从其他类访问它们。

package me.tylercreator.fallensurv.tracer;

public class MovementTracer implements Listener {

    public static ArrayList<String> ar = new ArrayList<String>();

    public static ArrayList<Block> blockplaced = new ArrayList<Block>();

    public static ArrayList<String> onlineplayerList = new ArrayList<String>();


我需要从其他包中的其他类访问它,例如包 me.tylercreator.fallensurv.spawnmodifier

标签: javaminecraft

解决方案


谢谢,但我刚刚发现我的 Eclipse 应用程序很愚蠢,不允许我编写 MovementTracer.ar(原因不明),现在它可以工作了,我正在从不同的包访问数组。!

我很快就会切换到 IntelliJ IDEA ,我认为这更好。


推荐阅读