Dioxin 29 Share Posted December 15, 2015 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 More sharing options...
Articron 738 Share Posted December 15, 2015 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 More sharing options...
Dioxin 29 Share Posted December 15, 2015 https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html 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 More sharing options...
Articron 738 Share Posted December 15, 2015 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 (Atleast that's what I've been fed @ uni ) Link to comment Share on other sites More sharing options...
Dioxin 29 Share Posted December 15, 2015 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 (Atleast that's what I've been fed @ uni ) 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: A 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 More sharing options...
darklord97 0 Share Posted September 5, 2018 i have write the most part of goblin fighter script but I, stuck on getting the eat part in could someone show me or sent a link to video that does Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.