Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • How to make a combat script


    qbots

    Recommended Posts

    It could still be null if there are no npcs that match the filter :)

    They're like landmines, aren't they? Didn't see that one. Might wanna consider creating a constant NONE value and returning that instead. Let the user decide whether they wanna perform behavior on "null" or not (make the null check optional).

     

    Although there might be too much code already relying on null. Might not be worth the hastle, but it would be pretty nice getting rid of those checks.

     

    And would NPC#getName ever return null?

    Link to comment
    Share on other sites

    They're like landmines, aren't they? Didn't see that one. Might wanna consider creating a constant NONE value and returning that instead. Let the user decide whether they wanna perform behavior on "null" or not (make the null check optional).

     

    Although there might be too much code already relying on null. Might not be worth the hastle, but it would be pretty nice getting rid of those checks.

     

    And would NPC#getName ever return null?

     

    https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html

    Link to comment
    Share on other sites

    I'm aware of Optional. I just find it pointless to create a wrapper object anytime an operation where "null" may be present is performed. It's a bandaid to the problem, and since Java doesn't support value types, it's not a cheap one. Value types were considered (http://cr.openjdk.java.net/~jrose/values/values-0.html), but there is currently no JSR for it (it's planned for a future release, but not anytime soon)

     

    Although Optional would be better than exposing null to clients, I personally prefer immutable constants. It's a lot cheaper

    Link to comment
    Share on other sites

    I'm aware of Optional. I just find it pointless to create a wrapper object anytime an operation where "null" may be present is performed. It's a bandaid to the problem, and since Java doesn't support value types, it's not a cheap one. Value types were considered (http://cr.openjdk.java.net/~jrose/values/values-0.html), but there is currently no JSR for it.

     

    Although Optional would be better than exposing null to clients, I personally prefer immutable constants. It's a lot cheaper

     

    I suppose working with an enum class and have them carry ReturnStates has its uses, and I do agree having these enum constants created on first static access would likely be less hungry than creating Optionals.

     

    Afaik a constant in java is final, and the term immutable is used for preventing object property changes after creation  :ph34r: (Atleast that's what I've been fed @ uni :P)

    Link to comment
    Share on other sites

    I suppose working with an enum class and have them carry ReturnStates has its uses, and I do agree having these enum constants created on first static access would be likely to be less hungry than creating Optionals.

     

    Afaik a constant in java is final, and the term immutable is used for preventing object property changes after creation  :ph34r: (Atleast that's what I've been fed @ uni :P)

    Yup, that's what those terms mean. Usually, constant refers to any identifier which may not change it's reference (which is what I'm referring to). But technically, in Java, a constant may only be a primitive or String created via a literal:

     

    constant variable is a final variable of primitive type or type String that is initialized with a constant expression 

     

    §4.12.4

    Link to comment
    Share on other sites

    • 2 years later...

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.