Questions tagged [null-check]

A check to see that an object has been instantiated.

A check to see that an object has been instantiated.

Typically, in a OO programming language, this is to see whether an object has been created or not.

e.g (Java example)

public void doStuff(Object obj) {
    if (obj != null) {
        // Do stuff with the object
    }
}
217 questions
2
votes
1 answer

How to properly annotate methods with generic collections using Eclipse external Annotations

I'm trying to annotate the method java.util.List.toArray using Eclipse's external annotations, but I'm not sure how to annotate the return type. If my List has the following signature: @NonNull List<@NonNull Element> List.toArray should…
looper
  • 1,929
  • 23
  • 42
2
votes
1 answer

unity "NullCheck" hold on to memory

"Null-Check" hold on to lots of memory. why? what happened? Anybody encounter the problem? Null-Check hold on to memory
wei zhong
  • 23
  • 2
2
votes
3 answers

Test if parent objects exists

I am using a lot of database data in my project that is exported in different classes. For example, I have transaction.Layout.Multimedia.Images.first(); The problem is that these properties are not necessarily available. So, it is possible that…
Jerodev
  • 32,252
  • 11
  • 87
  • 108
2
votes
2 answers

compareTo triggered at first add call on TreeSet in Java 1.7

I have a TreeSet with elements, and according to: http://docs.oracle.com/javase/7/docs/api/java/lang/Comparable.html#compareTo%28T%29 [ The natural ordering for a class C is said to be consistent with equals if and only if e1.compareTo(e2) == 0 has…
2
votes
1 answer

Null check emitted for 'this' access?

When you access an own instance field via the this reference (for example, an object or int field from a private method), the generated Android Dalvik bytecode will contain an iget bytecode instruction: iget v2, p0,…
Thomas Calc
  • 2,994
  • 3
  • 30
  • 56
2
votes
7 answers

difference between null != something and something != null

Is there a difference between null != something and something != null in Java. And if there is a difference then which one should I use and why??
M.J.
  • 16,266
  • 28
  • 75
  • 97
2
votes
5 answers

Does C# Have An Operation Similar to JavaScript's || Setter?

Does C# have a similar operation to JavaScript's || setter? For example, in JavaScript, if I want to check if a value is null and set a default, I can do something like this: function foo(val){ this.name = val || "foo"; } But, when I want this…
elucid8
  • 1,412
  • 4
  • 19
  • 40
2
votes
1 answer

Easy way to know which methods return null in .NET Framework

I want to be able to know which methods return null from .NET Framework. For example; when I call a search method from IQueryable, if the search did not find any results will it return null or an empty collection. We learn some of the methods but…
Mert Akcakaya
  • 3,109
  • 2
  • 31
  • 42
1
vote
2 answers

TypeScript says that variable is possibly `null` after `Array.prototype.includes(null)`

I have a multiple variable null check: const path = window.location.pathname const regex_list = path.match(/\d+/g) // 100% have at least 1 number const a = document.querySelector('') const b = document.querySelector('') if (![regex_list, a,…
Andrew15_5
  • 11
  • 4
1
vote
1 answer

Unity "null" == Check Failing?

https://i.stack.imgur.com/jyYpi.gif So I've been doing Unity C# programming for about 6 years now, and I only JUST found out about C# null v.s. Unity "null" (that's what you get when Unity is how you learn C# I guess). Needless to say, quite a…
1
vote
1 answer

Code Error is :- "Unhandled Exception: Null check operator used on a null value"

Error Code I have tried many condition for the Null check Operator but I couldn't find any solution regarding the Null check Operator. I want to Insert the data onto Sqlite Database that i have Created Named "LocalDatabase". When i Click Login…
1
vote
1 answer

Writing a more refined and simplified null check c#

I have the following code, bool HasPassed= (result!= null && result.Identifier.Equals("Passed"))? true : false This works fine as it is, but I was wondering if it were possible to write this code in a better and more simplified way, maybe using the…
Dre
  • 21
  • 4
1
vote
1 answer

Can I use `is` operator with inline variable declaration in Kotlin?

This is my first day of learning Kotlin and I have code like this: val tagInfo : UHFTAGInfo? = rfid.readTagFromBuffer() if (tagInfo != null) { val msg = hnd.obtainMessage() msg.obj = tagInfo hnd.sendMessage(msg) } Can I reduce it by one…
Kamil
  • 13,363
  • 24
  • 88
  • 183
1
vote
3 answers

Validating Nullable fields in Java

Let's say we have a class Product which has some nullable fields that are allowed to be null, for example, quantityAvailable and quantityReserved. I may want to validate these fields and throw an error, but since they are allowed to be null, I have,…
Rosa
  • 39
  • 5
1
vote
4 answers

What is the correct way to check for "possibly null" references?

I have this bit of relevant code: if (boardMap[i,j] != null) { Console.Write(boardMap[i,j].color.ToString() + " " + boardMap[i,j].type.ToString()); } else { Console.Write("X"); } boardMap contains potentially null values, which is why I…