Questions tagged [nullable]

The nullable tag is for issues relating to nullable members or types. A null is used to represent a missing or unknown value.

A data member is nullable if it can have the special value of NULL, instead of their common range of possible values. Nullable types are a feature of some statically-typed programming languages.

.NET

In , the built-in generic type System.Nullable<T> allows the programmer to use value types like int or DateTime with a value of null. Several .NET languages have a special syntax for declaring Nullable:

  • In , int? is an alias for System.Nullable<System.Int32>
  • In , Integer? is an alias for System.Nullable(Of System.Int32)

SQL

Null is a special marker used in SQL to indicate that data value do not exist in the database. Its proper use ensures various statistical aggregate functions perform correctly.

See more on Wikipedia.

D

The typecons module in package std has a templated struct - Nullable - for wrapping values types and allowing them to appear to have a null value (as in C#). Restriction is that the type must be able to be instantiated with T var or T var = T.init, where T represents the type being used.

Related tags

2417 questions
1
vote
2 answers

How to mix an upper bound with null values in a generic Kotlin class

I tried to derive a delegate class from AbstractList with an upper bound Comparable and want to use lists as delegate which can contain null values. Here's my implementation: package org.baier.test class MyList
S.Baier
  • 11
  • 3
1
vote
1 answer

Nullable types boxing in performance recommendations

Extracted from Unity perfomance documentation: Example of problematic boxing via nullable value types This code demonstrates a dummy particle class that one may create in a Unity project. A call to TryGetSpeed() will cause object allocation on…
Juxant
  • 106
  • 6
1
vote
1 answer

Assert.Equal trying to cast ushort? to 'string'

When a ushort? is passed to Assert.Equal it is trying to cast the two argumants to string. It works fine for int?. If I change the code to ushort test = 10; or Assert.Equal((ushort)10, test); or Assert.Equal(10, (ushort)test); it works fine. Whats…
KeepCalmAndCode
  • 207
  • 2
  • 12
1
vote
2 answers

C# 8 Nullable Reference Types Nested Guard

I've recently updated a project to utilize the C# 8 Nullable Reference Types feature. Everything in the solution works as expected, except for a custom Guard class that was written to reduce the number of keystrokes needed when creating Guard…
MarcusTheShogun
  • 469
  • 4
  • 14
1
vote
5 answers

Return a generic nullable Element

I'm trying to make a method that returns the highest value of an Array with generic elements that can be Nullable. public T Greatest(T?[] array) where T : struct, IComparable { T? Greater = null; foreach (var elem in array) …
RCPT
  • 303
  • 1
  • 3
  • 5
1
vote
2 answers

Can a returned value that can be null in java, be placed into a variable in kotlin which was declared as non null

As a pretty new developer in Kotlin, I encounter for the first time a situation that I will be glad to get explanation for. method findViewById of View can return null (this I know from knowledge as java developer but I will be glad to know if I can…
DorVak
  • 297
  • 2
  • 9
1
vote
1 answer

In F#, how to pattern match Nullable against Null?

(Really confused). Please assume I have a Visit downloaded from a WCF service as: type Visit = { tservice : Nullable } and a Visit array consisting of Visits. Assuming some of the visits in the array have a…
Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
1
vote
1 answer

Why I can't assign this variable to nullable? (Visual Basic)

I want to make that variable can be assigned with null. But giving'?' seems doesn't work. Please help me find the way out. I'm new to this. Thanks Public Class T3DObject Public V(7) As Point Public E(5) As Surface End Class …
1
vote
1 answer

Terminology: How would you describe the type T for Nullable?

When talking about a generic type, Foo, T is called the generic argument or type argument of generic type Foo in the .NET System.Type documentation. Now, when I am dealing with a type such as int? or Nullable, how do I refer to the generic…
Pierre Arnaud
  • 10,212
  • 11
  • 77
  • 108
1
vote
1 answer

Smart Cast with hashmap keys

I'm porting some Java apps to Kotlin, and I keep running into this issue with hashmaps. Let's say I have two hashmaps: var firstHashmap: HashMap = hashMapOf("foo" to "A", "bar" to "B") var secondHashmap: HashMap =…
arlomedia
  • 8,534
  • 5
  • 60
  • 108
1
vote
1 answer

What makes safe call (question mark) to be interpreted differently from classic if?

In Kotlin, if we declare a class member as var and nullable type, compiler doesn't allow us to run the member function although we put an if statement before calling the function because the compiler can't guarantee that the member isn't been set to…
Eitanos30
  • 1,331
  • 11
  • 19
1
vote
1 answer

Differences in models for GET and POST requests

I am creating a Web API using Asp .NET Core and am having troubles figuring out how to create my data models. Lets say I get the following model from the backend: public class Author : AuditEntity { public int Id { get; set; } …
J.Paravicini
  • 882
  • 12
  • 39
1
vote
0 answers

Why does java.util.Optional.ofNullable() expect @NonNullable?

Trying to wrap my head around why a utility class whose sole purpose is to wrap null, expects @NonNullable argument. Example below produces unexpected (to me) null type mismatch errors in Eclipse. Null type mismatch (type annotations): required…
tlum
  • 913
  • 3
  • 13
  • 30
1
vote
1 answer

TypeScript type exclude null include undefined

According to https://www.typescriptlang.org/docs/handbook/utility-types.html#nonnullabletype NonNullable Constructs a type by excluding null and undefined from Type. Example type T0 = NonNullable; // ^ = type T0 =…
SmoothTraderKen
  • 602
  • 4
  • 16
1
vote
1 answer

Problem assigning null to simulated generic nullable data types

I am trying to create a nullable data type in Delphi: type TNullable = record public Value: T; IsNull: Boolean; class operator Implicit(const AValue: T): TNullable; class operator Implicit(const AValue: TNullable): T; …
Paul
  • 25,812
  • 38
  • 124
  • 247