简体   繁体   中英

How to access arrayLists from other classes (possibly in other packages)

I need to access an ArrayList that I've created in my me.tylercreator.FallenSurv main class from other classes in other packages.

I have different packages , but i need every class to be able to access to certain ArraysList from a class.

I've tried to declare them as public static , but with that i can access them from other class only in the same file.

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>();


I need that to be accessed from other classes in other packages like package me.tylercreator.fallensurv.spawnmodifier

Thank you , but I just figured out that my Eclipse application was being stupid and didn't let me write MovementTracer.ar (for unknown reasons), now it works and I'm accessing the array from different packages.!

I'll soon switch to IntelliJ IDEA , which in my opinion is better.

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