Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. Hi, just wanted to comment on a post you made is this thread: https://www.spigotmc.org/threads/using-getstringlist-in-a-static-method.287621/#post-2773663
  2.  
  3. Static isn't "dangerous" - it exists for a reason, to be used in the right places.
  4. By creating instances of your utility classes you are completely _destroying_ the whole point of utility classes - they exist as part of the class, not the object, and are completely.
  5.  
  6. I'm not sure why you'd ever have utility classes set up like that by passing through a constructor, in fact the general rule is to have your utility classes marked as final with a private constructor to ensure no instances are constructed, as well as obviously making all fields and methods static.
  7.  
  8. What you should do is get an instance of your plugin class _in_ your utility class and access the methods that way. That is to say:
  9.  
  10. public final class SomeUtils
  11. {
  12.     private SomeUtils() {}
  13.  
  14.     private static final SomePlugin PLUGIN = JavaPlugin.getPlugin(SomePlugin.class);
  15.  
  16.     public static Something getSomething(SomeArgs... args)
  17.    {
  18.         return PLUGIN.getSomething();
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement