Solved List of classes that extend something

Discussion in 'Plugin Development' started by callum2904, Feb 4, 2015.

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

    callum2904

    ~ Thanks
     
    Last edited by a moderator: Feb 5, 2015
  2. Offline

    Skionz

    @callum2904 House extends Structure meaning House is a subclass of Structure and Structure is a superclass of House. Basically this means you can cast a House instance to Structure because House extends Structure, but you cannot cast Structure to House because Structure does not extend House. Sorry if my explanation was confusing. I used casting as an example, but the logic is the same for what your doing.

    tl;dr What your doing is syntactically correct.
     
  3. Offline

    sirrus86

    A house is always a structure, but a structure isn't always a house.
     
    xTrollxDudex likes this.
  4. Offline

    teej107

    @callum2904
    You can if the Structure is a House. If you attempt to cast to an object but that object isn't an instance of what you are trying to cast to, then a ClassCastException will be thrown. That is why it is good to do instanceof checks to make sure it is safe to cast.

    A great example in Bukkit is in the onCommand method with the CommandSender from the parameters. Some actions require a Player instance and Player is a CommandSender. However a CommandSender could also be other objects that are not related to Player which is why you should do an instanceof check before you cast to a Player.
     
    Skionz likes this.
  5. Offline

    callum2904

    @teej107 @sirrus86 @Skionz
    Thanks for your help for my last question, I have updated my OP with the errors I was getting that led me to question what I was doing with "Structure". If you can help I'd be happy and sorry if you are annoyed about me tagging you back.
     
  6. Offline

    mythbusterma

    @callum2904

    A WorldEdit Player wrapper does not extend Player, therefore it cannot be cast to one. Use the WorldEdit API to get the Player's wrapper from WorldEdit.
     
  7. Offline

    callum2904

    Quick question, do you know how to do that (just for quick answer), I am looking now if you don't.

    Doesnt matter I found how to do it.

    ~Thanks Everyone

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 10, 2016
Thread Status:
Not open for further replies.

Share This Page