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
4 answers

How to create a generic method that two Nullable Objects and a Class and returns a coerced non-null Value

I want to make a generic method that determines whether the first parameter is null, and if it is the case returns the second which is the default, else returns the first. Can I make this possible? I don't know how to implement it properly. public…
1
vote
3 answers

Using Java 8 Optional for safe fetching from Map

I have a nullable Map myMap in my Java 8 class. I need to fetch a value from the map based on the following condition. get keyA; if not present, get keyB; if not present, get keyC. I understand that Java 8's Optional brings the…
rsundhar
  • 115
  • 5
1
vote
1 answer

Checking whether an Optional object isn't Empty and null

I am working on sprint boot application, and I am working on SonarQube blocker resolving an issue. So I get one issue to be resolved: Ensure this "Optional" could never be null and remove this null-check. So I have changed the condition from myObj…
Neelam Sharma
  • 2,745
  • 4
  • 32
  • 73
1
vote
1 answer

Can cast pandas Series to `int64` but not to `Int64`

I am stuck with a weird type conversion issue.. I fill a pandas column of type 'float' with integer values. Naturally, they are represented as floating-point arithmetic figures, but still "accurate" to int precision. Converting them to int works…
KingOtto
  • 840
  • 5
  • 18
1
vote
2 answers

Best way to handle nullable json property in Dart?

Say I need to write this to assign a nullable DateTime property: t.vdate = json['vdate'] != null ? DateTime.parse(json['vdate']) : null; Is there a more compact way to do it?
Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95
1
vote
2 answers

type 'Null' is not a subtype of type 'Map' - Flutter

I'm getting the following error while fetching data from firestore but I know this error is not about how I'm fetching data. It is related to the null safety which was added in latest flutter update. I'm not so much familier with it. ════════…
Faizan Kamal
  • 1,732
  • 3
  • 27
  • 56
1
vote
1 answer

Kotlin unable to type-inference nullables indirectly

why can't kotlin infer when an object is not null through the boolean in which it was checked? In this example, there should be no condition in which melons is null. val berries = 13 val melons: String? = "big melons" val condition: Boolean =…
1
vote
1 answer

Nullable warning with EF Core fluent API

I have nullable enabled in VS2022. I don't see what the valid resolution to this nullable warning is. builder.OwnsOne(o => o.CreatedByUser, createdByUser => { createdByUser.Property(userRef => userRef.UserId) …
Beakie
  • 1,948
  • 3
  • 20
  • 46
1
vote
1 answer

How to safely test an unknown collection for null elements in Java?

Easy task, isn't it? Or? There is a little sentence in the Collection.contains contract, that makes it less easy: @throws NullPointerException - if the specified element is null and this collection does not permit null elements (optional) A small…
1
vote
1 answer

variables of nullable type - do they take up space when set to null?

Suppose I have an int variable defined in a C# program. Regardless of the value stored, it is always going to take 32 bits of memory. How do nullable types behave in this regard? If an int? variable is set to null, will it still occupy 32 bits of…
Aadith Ramia
  • 10,005
  • 19
  • 67
  • 86
1
vote
1 answer

interface as Nullable

I've got the following types/interfaces: type Nullable = T | null; export interface Employee { name: string; salary: number; } I don't want to define attributes of Employee to be Nullable, BUT the whole Employee should be Nullable. Since I…
axel wolf
  • 1,446
  • 3
  • 18
  • 29
1
vote
1 answer

Dictionary.TryGetValue and possible 'null' warning

I can't seem to wrap my head around the compiler's warning in this case: using System; using System.Collections.Generic; #nullable enable public class Program { public static void Main() { Guid guid =…
Ant
  • 181
  • 2
  • 14
1
vote
1 answer

About Nullable of C# generic parameter

Now I have a SomeClass with a constructor SomeClass(IList list). But when I use a List to construct it, the compiler told me: Cannot resolve constructor SomeClass(System.Collections.Generic.List>), candidates are:…
Mechanic Pig
  • 6,756
  • 3
  • 10
  • 31
1
vote
1 answer

C# IList Equals: Why is there a nullable compiler warning if the nullable typ could not be null?

I want to write my own Equals-method for two ILists. I've started with null checks and list entry counts. I thought I checked all possibilities,nevertheless after the null-checks I got the compiler-warning "Dereference of a possibly null reference."…
Spoomer
  • 38
  • 5
1
vote
2 answers

Can I force an expression to be used with a non-nullable parameter?

I'm not sure how to explain this, so I'm gonna show you some code first and explain what it does. Extension Filter: receives a parameter expression and a special type of filter I've built for my application (IFilter). public static…
Ricardo
  • 172
  • 9