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

How to make IntelliJ IDEA warn when null might be returned from lambda?

There are very useful code inspections in IntelliJ IDEA Constant conditions & exceptions and Return of 'null'. They show warnings when a method without @Nullable annotation returns null, a result of @Nullable method, @Nullable field or variable…
IlyaMuravjov
  • 2,352
  • 1
  • 9
  • 27
1
vote
2 answers

Allow Nullable Model in Views

The compiler appears to show an error when using a struct/ enum or any other value type as my MVC Model. CS0037 Cannot convert null to 'MyEnum' because it is a non-nullable value type I created a new MVC project (in VS 2019), created an…
serge
  • 13,940
  • 35
  • 121
  • 205
1
vote
1 answer

How to write a full property that is nullable

Sorry if it is a duplicate question, I can't find it... I want to write out a property, but still keep it nullable. I want public foo?: string; to be (but nullable) private _foo: string; public get foo(): string { return this._foo; } …
Hypenate
  • 1,907
  • 3
  • 22
  • 38
1
vote
2 answers

How to ignore null or empty values while using find() in Spring MongoRepository

I have a search functionality where there are different parameters and user can choose one or multiple parameters and ignore other parameters. I want to use findByFirstNameAndLastNameAndAddressAndCountry() for this so that if any parameter is null…
Chandan Kumar
  • 313
  • 4
  • 9
1
vote
2 answers

How to account for an argument to my method being `null` instead of an `int`

I need to know how to account for an argument to my method being null instead of an int . I have this method which is supposed to receive an int [HttpGet] public ActionResult UpdateUser(int userId){ } However when ever the session times out…
Joey Phillips
  • 1,543
  • 2
  • 14
  • 22
1
vote
1 answer

How to read null for null-able Boolean values

I am trying to read nullable values from a database. Right now my code is converting null values to false. How can I modify my code to allow for null values? Ap1ExamTaken = dr["AP1_ExamTaken"] != DBNull.Value &&…
smuldr
  • 315
  • 1
  • 12
1
vote
2 answers

Nullable as parameter

I've been trying to mess around with generic types and abstractions for a personnal library project but i'm facing a problem. I found this post that was kinda like what i wanted to do, but I wanted to push it a step further. because i wanted to…
Platypus
  • 321
  • 1
  • 4
  • 17
1
vote
1 answer

kotlin how does the checking of a nullable boolean work?

Having a class Config with nullable boolean sAllowed and a interface function returns a nullable Config interface IConfig { fun getConfig() : Config? } class Config (var sAllowed: Boolean?=null) and when want to use this boolean: var sAllowed…
lannyf
  • 9,865
  • 12
  • 70
  • 152
1
vote
2 answers

How to ensure a generic parameter is not Nullable?

I am trying to make a class GameOption that will hold three (really four) values: Name of Option as string An option as T A default value as Nullable< T > This how looks my class: public class GameOption { private T v; private string…
SkillGG
  • 647
  • 4
  • 18
1
vote
2 answers

Hint for @NonNull not working by pressing ALT+ENTER

I am getting problem in shortcut of Auto Insert code: ALT+ENTER Not annotated parameter overrides @ParametersAreNonnullByDefault Inspection info: This inspection reports problems related to @Nullable and @NotNull annotations usage configured in…
1
vote
2 answers

List RemoveLast Element and returning it with T being nullable

While I don't quite understand why C# doesn't provide collection methods that remove AND return elements in one command I try to write my own custom extensions ... public static T RemoveLast(this List list) { if (list.Count >…
BadmintonCat
  • 9,416
  • 14
  • 78
  • 129
1
vote
0 answers

= operator applied to nullable types in VB

I am quite surprised that in C#: int? a = null; int? b = null; intc = a == b; //c = true While in VB: Dim a As Integer? = Nothing Dim b As Integer? = Nothing if( a = b ) generates an exception because the condition a = b is apparently resolved to…
A.D.
  • 1,062
  • 1
  • 13
  • 37
1
vote
3 answers

Is there an elegant kotlin way of convincing the compiler that a nullable field to which I just assigned a real value can't be null anymore?

I have read that using !! should generally be avoided. Is there a way to write the following code in a more elegant way without having to add something like obsolete null checks and duplicated or dead blocks of code? class A(var field: Thing?) { …
maths.js
  • 33
  • 6
1
vote
0 answers

Automatically generate nullable and not-null types in overriden methods

I'm trying to extend a CameraCaptureSession.StateCallback. So I use Ctrl+O to select methods to be overriden. Android Studio 3.3 sees methods' parameters like platform types: session: CameraCaptureSession!. However if I open the sources (SDK 27), I…
SerVB
  • 129
  • 17
1
vote
3 answers

How to affect to a boolean value the result of a boolean? expression

I would like to code in VB the equivalent of this in C#: bool? a = whatever; bool b= (a==true); VB compiler does not accept this: Dim a As Boolean? Dim b As Boolean = (a = True) I suppose in this context, it interprets (a = True) as an affectation…
A.D.
  • 1,062
  • 1
  • 13
  • 37