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
1 answer

"Variable expected" error when calling getValue on a mutable map with a nullable type

I'm having a problem with altering the value of a mutable map. I assume it's something to do with nullable types, but I'm not sure. The code producing the error is below: fun countHexadecimalNumbers(codes: List): Map { val map =…
Connor
  • 867
  • 7
  • 18
1
vote
0 answers

How to inform the compiler that a generic method has set the property of its return value to something that is not null?

I am using C# 8.0 with nullable errors turned on. I have a method in which the nullable property of the return type is set to something other than null. Both the return type and its property are going to be used so just returning the property is not…
1
vote
1 answer

Flutter nullable error when creating class parameterized constructor

I updated flutter stable version 2.2.1 (Nullable feature enabled). When I write constructor of the class as following code, I got error as following image shows. Please help me to resolve this. class FlavorBanner extends StatelessWidget { final…
Malisha De Silva
  • 393
  • 2
  • 10
1
vote
2 answers

Does a function without a return statement always return null in Flutter?

The return type of the following function is Future and yet the compiler does not complain that there is no return value if the picker did not return a picture. static Future takeImage() async { PickedFile? pickedFile = await…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
2 answers

C# compare native type with nullable type (Int32 with Int32?)

Is there a way to compare nullable and non-nullable generics in C#? For example: public void function() { Type t = sqlreader.GetValue(pos).GetType(); } where t is of type Int32 and T is of type Nullable. How can we compare t and T…
DreX
  • 333
  • 1
  • 5
  • 17
1
vote
1 answer

Ordering a NodaTime Nullable OffsetDateTime

I have a class Appointment that contains a nullable NodaTime.OffsetDateTime property. If I have a list of Appointments, how would I use Linq OrderBy to order this list with the null StartDateTime first then StartDateTime in descending order? Class…
Ayb4btu
  • 3,208
  • 5
  • 30
  • 42
1
vote
1 answer

BitmapFactory.decodeFile() returning null for existing image

I am facing an issue now. Why Bitmap.decodeFile() method is returning null? I tried with the following advice. but the above advice doesn't help me. For directories reference Code: private File createPhotoFile() throws IOException { …
KangDo
  • 79
  • 9
1
vote
2 answers

avoid Value property for nullable value types?

If I have a nullable value type I always have to use its Value property, even after I checked it for null. Is there a consise way around it? public void Foo(SomeStruct? s) { if (s != null) { DoIt(s.Value.x + s.Value.y + s.Value.z); …
codymanix
  • 28,510
  • 21
  • 92
  • 151
1
vote
1 answer

Visual Studio Code reports error in Typescript code when null is assigned to a typed variable

I have the following interface: interface CompositeNodeInterface { name: string; definer: any; parent: CompositeNodeInterface; children: [CompositeNodeInterface]; addChild(definer: any): CompositeNodeInterface } As you can see, attribute…
HuLu ViCa
  • 5,077
  • 10
  • 43
  • 93
1
vote
3 answers

How to create null safe block in flutter?

How do I null check or create a null safe block in Flutter? Here is an example: class Dog { final List? breeds; Dog(this.breeds); } void handleDog(Dog dog) { printBreeds(dog.breeds); //Error: The argument type 'List?' can't…
Joel Broström
  • 3,530
  • 1
  • 34
  • 61
1
vote
1 answer

Flutter: Firebase Analytics not compatible with null safety

I tried to move my project to the new Dart and make it null safety compatible but seems firebase_analytics is still not ready. How can I bypass this error, are they going to release firebase_analytics null safety soon? I filed an issue here:…
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
1
vote
0 answers

How does C# check the nullability of out parameters?

I am currently experimenting with the nullable reference type features of C# 8.0 in .NET 5 (C# 9.0) and I noticed that the compiler correctly checks the nullability of out parameters in TryParse and TryGetValue. For example: var dict = new…
Michael Chen
  • 574
  • 3
  • 11
1
vote
1 answer

newtonsoft json deserialize of valid datetime into nullable datetimeoffset different behavior if target in class was initialized

Newtonsoft JSON pulled today from NuGet (V12 I think), .NET framework V4.7.2, simplified example of web service return. Code and output follows. All returned datetime forms are claimed to be UTC. Is there a deserialize setting option to treat no…
1
vote
4 answers

Nullable enum type cannot be assigned to null when used as a generic

I'm using C# 9 and I ran into this odd problem, so I wrote a simple example below that demonstrates it. I need to set the value of a nullable enum to null, but I get an error when doing it through a generic type. If I hard-code the enum type into…
Cains
  • 23
  • 6
1
vote
1 answer

PHP nullable type declaration

Is there any difference between this function in PHP 7.4? public function foo(string $argumentThatCanBeNull = null) {} public function bar(?string $argumentThatCanBeNull = null) {}
Simo Pelle
  • 141
  • 1
  • 11