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

Type conversion error CS0029 when filtering list of nullable enums using LINQ

This code compiles just fine: public record Foo ( double X ); private static void Test() { IImmutableList myList = ImmutableList.Empty.Add(new Foo(42)).Add(null); IImmutableList myCleanedList = myList.Where(foo => foo…
Joerg
  • 790
  • 2
  • 10
  • 23
1
vote
2 answers

Object null-ness check in Java

Which one is recommended and to be used to check the Object null-ness? null != Object or Object != null and other way null == Object or Object == null ...and is there any difference between them?
Mahendra Athneria
  • 1,203
  • 3
  • 16
  • 32
1
vote
1 answer

How to mark a type as not null?

I want a generic method (or class) to behave something like this: val instanceS = MyCoolClass() instanceS.someMethod("some not null string") //compiles instanceS.someMethod(null) //doesn´t compile val instanceS2 =…
caeus
  • 3,084
  • 1
  • 22
  • 36
1
vote
2 answers

Why do I get this error: _CastError (Null check operator used on a null value)

I have a column like this: Column(children: [ product.videos![product.videoIndex].videoUrl != null && product.videos![product.videoIndex].videoUrl != "" ? VideoPlayerWidget( videoAddress:…
best_of_man
  • 643
  • 2
  • 15
1
vote
3 answers

Adding a column efficently in SQL Server

I want to add an integer column to a table with a large number of rows and many indexes (Its a data warehouse Fact Table). To keep the row width as narrow as possible all the columns in this table are defined as not null. So I want the new column to…
cindi
  • 4,571
  • 8
  • 31
  • 38
1
vote
1 answer

Operator call corresponds to a dot-qualified call 'n.compareTo(3)' which is not allowed on a nullable receiver 'n'

I have the following code: val n = readln().toIntOrNull() if (n > 3) { println(n) } I am receiving above subject error: Operator call corresponds to a dot-qualified call 'n.compareTo(3)' which is not allowed on a nullable receiver…
Jaguar
  • 15
  • 6
1
vote
1 answer

Make all fields in Java Immutable Nullable

@Immutable @Modifiable public interface Record { String id(); String fName(); String lName(); String mName(); } All the fields in Record can be Nullable. One way for me to make these fields Nullable is to add @Nullable…
Adi
  • 387
  • 3
  • 6
  • 14
1
vote
1 answer

Optional.ofNullable() on List

I need an assistance on one of the optional concepts of java 8+. I have been seeing developers using Optional.ofNullable on list object which is incorrect and I am not sure how its been working perfectly without bugs/defect. Code goes this way Note:…
Sachi97
  • 39
  • 8
1
vote
2 answers

Migrate to ObserveAsState in Jetpack Compose - null

I am a beginner trying to learn Kotlin by changing an old tutorial to Compose. I have a ViewModel with private val _registerStatus = MutableLiveData>() val registerStatus: LiveData> = _registerStatus fun…
1
vote
1 answer

ModelState.IsValid is false when I have a nullable parameter and send it as null

Here the nullable parameter using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; namespace RenoshopBee.Models { public…
1
vote
1 answer

Flutter: How can I remove the ”?" if I'm sure the instance is not null?

I have a function like this: Map _chapterInfoMap = HashMap(); ChapterInfo? getChapterInfo(int id) { ChapterInfo? info = _chapterInfoMap[id]; if (info == null) { // do some other thing to find info. if I still get null,…
1
vote
1 answer

Razor Pages ModelState is different (invalid) when "nullable" types are enabled. WHY?

I have tried to copy/rewrite that code for learning purposed and realized after far to much hours: sneakly hidden before all the using statements: #nullable disable It was driving me insane, that in my code (opposed to example) that the ModelState…
somedotnetguy
  • 557
  • 2
  • 14
1
vote
1 answer

Can I make IParsable accept nullable?

I want to make safe, generic extension method for string? parsing: /// /// Returns parsed value if success, otherwise default value /// public static T? ParseTo(this string? value, IFormatProvider? formatProvider = null)…
Pawel
  • 891
  • 1
  • 9
  • 31
1
vote
1 answer

Entity Framework - how to handle Nullable in entity

I have an entity(EF) with property int? priority. I want to work with the entity across my platform. Dictionary tasks = new Dictionary(); tasks.Add(task.Priority, task); in the second row, I want to get Priority out of task and…
SexyMF
  • 10,657
  • 33
  • 102
  • 206
1
vote
2 answers

Nullable DateTime, EditorTemplates, JQ UI DatePicker

My intent was to apply the JQuery UI Datepicker to my entire site by creating an EditorTemplate as per this post ASP.NET MVC 2 Templates @model DateTime @{ string name = ViewData.TemplateInfo.HtmlFieldPrefix; string id = name.Replace(".",…
Greg Hayden
  • 135
  • 1
  • 3
  • 12