Global variables and arraylist/hashmaps?

Discussion in 'Plugin Development' started by danielh112, Nov 6, 2013.

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

    danielh112

    How can I make it so that the following things can be accessed from any class in my plugin?
    • variables
    • arraylists
    • hashmaps
    Thank you in advance!
     
  2. Offline

    sd5

    danielh112 Mark them as public, then you can access them from everywhere:
    Code:java
    1. public class Foo {
    2. public int foo = 0;
    3. }


    Then you can access it from everywhere with an instance of Foo:
    Code:java
    1. Foo instance = new Foo();
    2. int foo = instance.foo;


    Another possibility is to mark them as "static" so you don't need an instance of the class:
    Code:java
    1. public class Foo {
    2. public static int foont = 0;
    3. }


    And you can access it from everywhere with:
    Code:java
    1. int local = Foo.foont;
     
  3. Offline

    danielh112

    thank you very much that is perfect!
     
Thread Status:
Not open for further replies.

Share This Page