Development Assistance Arraylist, Help!

Discussion in 'Plugin Help/Development/Requests' started by Guuuuui, Nov 8, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    I created a arraylist in a class, and now I want to use this arraylist in another class, how I do?


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 14, 2016
  2. Offline


    For those who came here looking for an answer he either made the arraylist static by placing "static" where it's defined, or made a getter/setter for the arraylist.
  3. Offline


    Or he made it public, which isn't usually a good idea--but static fields shouldn't be public, either, unless they're final. :)
  4. Offline


    True, though there are some cases where static fields should be public like a popular singleton method where the constructor(s) is private and you have a public static instance of that class defined to create a new instance of said class.

    For example

    2. public static instance = new Test();
    3. public class Test
    4. {
    5. private Test()
    6. {
    7. ...
    8. }
    10. }

    Now people can access public fields/methods with Test.instance :D
  5. Offline


    caelum19 No, that should either be final, or it should be a getter. (It should also be inside the class.)

    If it's a true singleton, it should be final. However, since it's not a scalar, I would probably still use a getter. What if I have multiple contexts in the future and want to have a separate instance for each one?
  6. Offline



    Oops... yeah I forgot to put it inside the class ¯\_(ツ)_/¯

    The points you made make sense, I'll be using getters from now on.
    Tad confused on that multiple contexts bit though, what do you mean?
  7. Offline


    Worlds are a good example. Back in the day, there was only one world, and it was a singleton. It's easier to transition away from a singleton when you're using getters, though it still takes some work. I try to avoid singletons, and instead pass around a "context" object between classes that stores any would-be singletons. That way, I can create different contexts in the future.
  8. Offline


    can anybody explain getter and setter for me
Thread Status:
Not open for further replies.

Share This Page