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

Scala: how to determine if a type is nullable

I have two questions about nullable types in Scala: Let's say I wish to define a new class: class myClass[T](x: T), and I'd like to make sure that T is nullable. How do I do that? I'd like to write a function def myFunc(x: T) (not as part of the…
shakedzy
  • 2,853
  • 5
  • 32
  • 62
1
vote
7 answers

C# - Methods for null checking

What's the preferred way of checking if the value is null? Let's say we have some entity, which has properties, which can be null (some of them or all of them). And I wish to check this in runtime, if some property is actually null or not. Would you…
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
1
vote
1 answer

Kotlin generics change return type

I have this method in Java I want to convert to Kotlin, but still use from both Java and Kotlin: @Nullable public static T nullIfEmpty(@Nullable final T t) { return TextUtils.isEmpty(t) ? null : t; } In another place I…
Gesh
  • 433
  • 3
  • 9
1
vote
2 answers

LINQ compiled query struggling with nullable int

I have the following compiled Linq query: public static readonly Func GetUnreadNotificationID = CompiledQuery.Compile((DBContext db, Models.User forUser, Type notificationType,…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
1
vote
5 answers

Handling DateTime? in NHibernate/LINQ queries

this is a follow-up to question Better DateTime? or use default(DateTime) for NULL? I tried to implement a simple query that works with DateTime? with a different example rather than the one of the other question. In my case I have public virtual…
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
1
vote
2 answers

Does Reason support nullable types?

This is a newbie question, but I couldn't find a quick answer anywhere. Does Facebook's Reason language support nullable types? If so, in what form?
Tin Man
  • 700
  • 8
  • 29
1
vote
3 answers

Is there a nicer way to write this in kotlin?

This is my current code: private val EXTRA_IS_REFRESHING = "IS_REFRESHING" private var isRefreshing: Boolean = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) isRefreshing = if…
Gavriel
  • 18,880
  • 12
  • 68
  • 105
1
vote
4 answers

Android parcelable - write nullable long

I have my parcelable class Article: class Article : Parcelable { var image: Long? = null var category: String? = null var videos: String? = null constructor(data: JSONObject) { if (condition) image = 50000L category…
Ravers
  • 988
  • 2
  • 14
  • 45
1
vote
1 answer

Assign NULL into SQL Server datetime column using vb.net in asp.net

I have 3 textboxes in my app. the 3rd one is for date of birth which user can keep empty. The app saves the values entered by the user into a SQL Server database that has a table with 3 columns. The birthday column's datatype is set to Date and it…
Masarwa
  • 43
  • 8
1
vote
1 answer

Validating Model Properties but allow null values

I am trying to get a model property validation to work but allowing a null value in a string property. The Property i'm trying to validate is a: public string PhoneNumber { get; set;} And i am validating it like this: [Phone(ErrorMessage =…
H4p7ic
  • 1,669
  • 2
  • 32
  • 61
1
vote
1 answer

c# Reflection deep copy set Datetime values

I am trying to deep copy a complex object that has some date properties. I am getting "The value '' could not be converted to a valid date" error. I am using below code for copying:- private static object CloneProcedure(Object obj) { if…
Kavya Shetty
  • 185
  • 2
  • 14
1
vote
1 answer

What is the cleanest way to see if a nullable type has a value, and if it does, to compare the value to another non-nullable type's value?

I have two nullable enums which I would like to compare the value of to two regular enums. If the nullable enums do not have a value, I want the comparison to evaluate to true. This is what my logic looks like so far: if (!nullableEnumOne.HasValue…
arc54
  • 41
  • 5
1
vote
1 answer

Performance of class with short circuit getters vs lazy getters

So I have a math class which performs calculations on the getters of a number of properties. Now I converted these properties so that after their first evaluation return only that result from then on. Now concerning performance I was wondering that…
zman
  • 333
  • 1
  • 2
  • 9
1
vote
1 answer

Where can I find an Eclipse External Annotations file for the JDK8?

I intend to work with Eclipse External Annotations. Where can I find the EEA set for the JDK8? https://wiki.eclipse.org/JDT_Core/Null_Analysis/External_Annotations
Jörn Guy Süß
  • 1,408
  • 11
  • 18
1
vote
2 answers

.add Method of MutableList throws kotlin.KotlinNullPointerException

Please, just keep in mind that I'm ramping up on functional programming hehe. I have defined a Mutable list like this: var list: MutableList? = null So, when I try to use list!!.add(E()) this throws a kotlin.KotlinNullPointerException. I…
Jimmy Alvarez
  • 587
  • 1
  • 5
  • 13