Questions tagged [non-nullable]
232 questions
8
votes
1 answer
What is the default value of Non-Nullable reference types in C# 8?
If I enable nullable reference types, what will be the value of the following string if I declare it like so?
string text;

Hrant Khangulyan
- 99
- 4
8
votes
2 answers
Is it possible to document that return value is not null with Java Optional?
Is it possible to document that return value is not null with Java Optional?
Most tools and frameworks care only about arguments but I'd like to express in type that return value is not null (instead of doing that in JavaDoc).
UPDATE Looks like you…

gavenkoa
- 45,285
- 19
- 251
- 303
8
votes
1 answer
IntelliJ IDEA @ParametersAreNonnullByDefault for all subpackages
I use IntelliJ's null-checking mechanism to prevent nullpointer crashes.
I've successfully set up all Java method parameters to be @NonNull by default using this answer.
After creating package-info.java which is used to define package annotations in…

kosiara - Bartosz Kosarzycki
- 10,922
- 12
- 70
- 83
7
votes
4 answers
Cannot specify a culture in string conversion explicitly when converting nullable decimal (decimal?) to string
I have a property:
public decimal? DejanskaKolicina { get; set; }
and Resharper shows me:
specify a culture in string conversion explicitly
But if I use:
DejanskaKolicina.ToString(CultureInfo.CurrentCulture)
I always get the message…

senzacionale
- 20,448
- 67
- 204
- 316
7
votes
7 answers
About the non-nullable types debate
I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion dollar mistake, and Spec# has introduced non-nullable types to combat this…

zildjohn01
- 11,339
- 6
- 52
- 58
7
votes
1 answer
Can we ensure nullability of `+ (nonnull instancetype)sharedInstance;`?
This is a question on how to gracefully circumvent the nullability of init in NSObject class.
So here is a classic objective-c implementation:
+ (instancetype)sharedInstance
{
static dispatch_once_t onceToken;
static id sharedInstance;
…

Cœur
- 37,241
- 25
- 195
- 267
7
votes
1 answer
Eclipse null analysis: The expression of type int needs unchecked conversion to conform to '@Nonnull Integer'
When configuring Eclipse 4.2.0 to perform a null analysis (configured to use @javax.annotation.Nonnull etc.), the following code will generate the warning
Null type safety: The expression of type int needs unchecked
conversion to conform to…

Marco Eckstein
- 4,448
- 4
- 37
- 48
7
votes
1 answer
Getter and @Nonnull
I get a warning from eclipse and I know I can remove it with suppress warning but I'd prefer to understand what makes it thing it could be null.
package-info.java
@ParametersAreNonnullByDefault
package test;
import…

xavierm02
- 8,457
- 1
- 20
- 24
6
votes
3 answers
What is the difference between using `late` keyword before the variable type or using `?` mark after the variable type it in the Flutter?
I think in new Dart rules the variables can not be declared/initialized as null. So we must put a late keyword before the variable type like below:
late String id;
Or a ? mark after the variable type like below:
String? id;
Are these two equal Or…
user11874694
6
votes
1 answer
'android.annotation.NonNull' is not public in 'android.annotation'. Cannot be accessed from outside package
I get this warning when I try to list data.
Does anyone know why?

Onur Nebioğlu
- 73
- 1
- 4
6
votes
1 answer
How to mark a default return value in C# 8 as nullable for classes only?
I'm currently trying to apply the new C# 8.0 non-nullable reference type feature to existing code, and don't know how to fix the CS8603 warning in the following data deserialization method:
T ReadOptional() where T : IEntity, new()
{
if…

Ray
- 7,940
- 7
- 58
- 90
6
votes
1 answer
Why Are @NonNull Annotation on FQN Not Allowed?
Is it a bug in Eclipse or why I can't annotate parameters with fully qualified type names (FQN) with @NonNull?
import org.eclipse.jdt.annotation.NonNull;
public class Foo {
// No problem
public void bar(@NonNull String x) {
…

Vertex
- 2,682
- 3
- 29
- 43
5
votes
1 answer
Non-nullable reference types (yet again)
There have been many questions around support for non-nullable reference types in .NET. The great hope was code contracts, but it is limited to runtime checking for those who have limited budget.
As for approaches other than Code Contracts, Jon…

Akash
- 2,311
- 1
- 20
- 37
5
votes
1 answer
"Non-nullable event must contain a non-null value when exiting constructor"
Im getting the warning "Non-nullable event 'SomeEvent' must contain a non-null value when exiting constructor. Consider declaring the event as nullable."
Here's a very simplified version of my code which replicates the exact same problem. What am I…

ruwenzori
- 61
- 1
- 3
5
votes
1 answer
C# Generic class: infer non-nullable type from nullable type parameter
I use C# 8 nullable reference types.
I have a generic class that might accept nullable reference type as a type parameter.
Is there a way to declare non-nullable type based on generic type parameter that might be nullable reference type (or even…

Liero
- 25,216
- 29
- 151
- 297