I have a class which is not derived from a Plugin. This class needs access to the PluginApi. I'm wondering if I could just set a static variable in the class with the value of getApi() obtained from the main BasePlugin class so that I don't have to always pass getApi() in as a parameter. In other words, does getApi() always return the same value or can it change over the lifetime of the extension?
Code:public class Main extends BasePlugin { @Override public void init(EsObjectRO parameters) { // This? OtherClass.api = getApi(); OtherClass.getRooms1(1); // Or this? OtherClass.getRooms2(getApi(), 1); } } public class OtherClass { public static PluginApi api; static void getRooms1(int zoneId) { Collection<RoomValue> rooms = OtherClass.api.getRoomsInZone(zoneId); } // Or is this needed static void getRooms2(PluginApi api, int zoneId) { Collection<RoomValue> rooms = api.getRoomsInZone(zoneId); } }


Reply With Quote
