Understanding one thing.

Discussion in 'Spigot Plugin Development' started by Deger, Jun 4, 2016.

  1. Hi, can someone explain what does mean? Is it a object?
    "Main plugin;"

    Main = my main class
    plugin is the name

    Is it the same aas?
    Main plugin = new Main();
     
  2. Serializator

    Supporter

    You would know if you learned Java.
     
    • Winner Winner x 2
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  3. Well, he is asking for help and all you do is post a useless comment.
     
    • Optimistic Optimistic x 1
  4. Serializator

    Supporter

    I do that because as far as I know this forum is here to provide help with problems when someone is working with the Spigot API, not if he has problems with Java itself, and it gets quite annoying.

    It has been said thousands of times, this isn't a place to learn Java, you should know Java properly before using the Spigot API.
     
    • Agree Agree x 1
  5. I know that. I said that he was asking for help and you posted a useless comment. If you're not going to help him, then why post if it's not going to make any difference?
     
    • Optimistic Optimistic x 1
  6. Serializator

    Supporter

    You have to be kidding me, right?
    The only thing he needs to look up is "Learning Java", "Java Tutorial", "Java Guide", "Programming in Java".
     
    • Agree Agree x 1
  7. Okx

    Okx

    Main plugin; can be split into two things: the type of the object, and the name.
    In this case, the object is of type Main, and the object's reference name is plugin.

    Main plugin = new Main(); is not the same, because we are initializing it (because of the =). This is constructing an object of type Main. With the other object, it hasn't been assigned a value and is useless. Constructors can be defined like this:
    Code (Text):
    public Main(args) {
      // setup default values... etc
    }
    By default, a class has a default public constuctor that takes no arguments and does nothing. This default constructor is only applicable if there are no constructors in that class.
     
    • Like Like x 1
    • Informative Informative x 1
  8. Thanks.
     
  9. Just because i did not post a code, doesnt mean i dont have one......
     
    • Funny Funny x 1
  10. Serializator

    Supporter

    That's not what I mean, the question you asked is literally basic Java, literally the thing you learn at the beginning of each tutorial/guide.
     
    • Agree Agree x 1
  11. Note that you should never use 'new Main()' if Main is the main class of your plugin. That does the plugin loader of the server for you and you should use that instance which you can access with 'this' in the main class.
     
    • Agree Agree x 1
  12. Anyways,
    Main plugin; is the same as: Main plugin = null;

    Main plugin = new Main(); is a nono.
    Use 'this' if it's in the Main class, or Main.getPlugin(Main.class);
    Or just constructors..

    Basically, it's a reference to the Main class.
     
    • Funny Funny x 1
  13. Serializator

    Supporter

    To elaborate on what you said about "Main plugin;" (just to avoid confusion if people get errors because of not setting a value of a variable) being the same as null, in this case it is, but if the variable was a local variable it has to be explicitly be set to a value, even it that value is null.

    If that didn't make sense, read this thread on StackOverflow.
     
  14. Yeah, I guess. He'd quickly notice he can't use an unset variable at all, though, if his IDE is smart, so he'd have to null it.
    Basically same as null, then.