null-check

Why does String.Equals(Object obj) check to see if this == null? [duplicate]

我们两清 提交于 2019-12-23 09:18:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why check this != null? // Determines whether two strings match. [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)] public override bool Equals(Object obj) { //this is necessary to guard against reverse-pinvokes and //other callers who do not use the callvirt instruction if (this == null) throw new NullReferenceException(); String str = obj as String; if (str == null) return false; if (Object

Null or empty check for a string variable

这一生的挚爱 提交于 2019-12-21 06:55:26
问题 if((isnull(@value,''))='') I want to know whether the above piece of code works in checking if the variable is null or empty. 回答1: Yes, that code does exactly that. You can also use: if (@value is null or @value = '') Edit: With the added information that @value is an int value, you need instead: if (@value is null) An int value can never contain the value '' . 回答2: Use This way is Better if LEN(ISNULL(@Value,''))=0 This check the field is empty or NULL 回答3: Yes, you could also use COALESCE(

Java Object Null Check for method

狂风中的少年 提交于 2019-12-17 16:28:54
问题 I need to create a null check in this formula for the books[i] and I am not entirely sure how to go about this as I am not greatly familiar with null checks and very new at programming. Any and all help is much appreciated! public static double calculateInventoryTotal(Book[] books) { double total = 0; for (int i = 0; i < books.length; i++) { total += books[i].getPrice(); } return total; } 回答1: First you should check if books itself isn't null, then simply check whether books[i] != null : if

Why the overall performance of application degrades if I do null checks on the maps?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 08:07:40
问题 Below is my class which uses CountDownLatch to make sure reads are not happening on the primary, secondary and tertiary maps for the first time whenever writes are happening on those maps. public class ClientData { public static class Mappings { public final Map<String, Map<Integer, String>> primary; public final Map<String, Map<Integer, String>> secondary; public final Map<String, Map<Integer, String>> tertiary; public Mappings( Map<String, Map<Integer, String>> primary, Map<String, Map

javax.annotation.Nonnull vs assert

≯℡__Kan透↙ 提交于 2019-12-12 09:34:32
问题 I'm using Findbugs and javax.annotation.Nonnull on method parameters. On private methods I usually add an assert line to check for nullness like private void myMethod(@Nonnull String str) { assert str != null .... Latest Netbeans version (7.3rc2) is reporting that the assert check is not necessary (because of the Nonnull annotation). I'm not fully sure this is a Netbeans bug or not. Can the assert line be removed because I specified the @Nonnull annotation ? As far as I understand, the

Can IntelliJ auto-generate code to null-check arguments when using @ParametersAreNonnullByDefault annotation on package

孤人 提交于 2019-12-11 15:05:10
问题 I like the feature where IntelliJ can automatically generate code to check at runtime for null on each argument/parameter passed to a method. This feature is enabled in Preferences > Build, Execution, Deployment > Compiler > Add runtime assertions for notnull-annotated methods and parameters (checkbox). The neighboring Configure annotations button configures which annotation package. I am trying to set my not-null annotation at the package level. Example: @ParametersAreNonnullByDefault

Is it necessary to check null values with constructor injection?

浪子不回头ぞ 提交于 2019-12-11 13:05:42
问题 I'm using .NET Core constructor injection. In a code review from a colleague, he raised the question if I should check for null values on injected dependencies in controllers. Since the framework is responsible for creating an instance of the service, it seems to me that it would take care of any errors and never have a null value dependency passed to a constructor. I don't have any factual evidence for this though, so I'd like to know if it's possible that a null check may be necessary. For

Is there a simple way to check unsafe expression in C++?

╄→гoц情女王★ 提交于 2019-12-10 23:09:35
问题 I'm trying to find a [better] way to run/check a potentially unsafe expression or perform multiple null checks in a more elegant way. Here is an example of codes I would like to improve: if (myObjectPointer && myObjectPointer->getSubObject() && myObjectPointer->getSubObject()->getSubSubObject() && myObjectPointer->getSubObject()->getSubSubObject()->getTarget()) { // Use safely target ... *(myObjectPointer->getSubObject()->getSubSubObject()->getTarget()) ... } I tried to find a more elegant

JS object null checking - weird JS problem [duplicate]

谁都会走 提交于 2019-12-10 21:37:56
问题 This question already has answers here : Why don't logical operators (&& and ||) always return a boolean result? (9 answers) Javascript AND operator within assignment (6 answers) Closed last year . Imagine this simple scenario. I have variable that can be plain JS object with one property, ID, that is a number or obj variable can be null. I have simple test() function that checks if the variable is not null and that it must have valid id property. var obj = { id: 111 }; function test() {

javax.annotation.Nonnull vs assert

孤人 提交于 2019-12-04 23:30:56
I'm using Findbugs and javax.annotation.Nonnull on method parameters. On private methods I usually add an assert line to check for nullness like private void myMethod(@Nonnull String str) { assert str != null .... Latest Netbeans version (7.3rc2) is reporting that the assert check is not necessary (because of the Nonnull annotation). I'm not fully sure this is a Netbeans bug or not. Can the assert line be removed because I specified the @Nonnull annotation ? As far as I understand, the annotation is used only during static analysis while assert is, when enabled, active during execution so the