non-nullable Questions

2

Solved

2

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 ...
Anticipant asked 22/10, 2021 at 12:1

2

Solved

When I write this statement: var x = new ClassName(); x is implicitly typed as a ClassName?. That is, since ClassName is a reference type, implicit assignments using var automatically define as nul...
Collotype asked 10/1, 2023 at 22:23

8

Solved

I'm designing a language, and I'm wondering if it's reasonable to make reference types non-nullable by default, and use "?" for nullable value and reference types. Are there any problems with this?...
Coppins asked 28/3, 2009 at 19:9

4

I have some non-nullable fields which I want to initialize inside a helper methods, called from a constructor, to reduce the clutter inside the constructor: private FlowLayoutPanel _flowPanel; priv...
Connell asked 28/10, 2021 at 9:22

3

Solved

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 t...
Ptolemaeus asked 29/9, 2021 at 1:2

4

Solved

If I have a nullable type Xyz?, I want to reference it or convert it to a non-nullable type Xyz. What is the idiomatic way of doing so in Kotlin? For example, this code is in error: val something:...
Deliciadelicious asked 28/12, 2015 at 18:13

3

Solved

I added non-nullabe in pubspec as well. I don't want to change my SDK version, cuz I have already been using it for other dependencies and it will cause errors if I change the version. Please let m...
Sinkage asked 8/5, 2021 at 14:27

3

Solved

num should be nullable when set, but what it returns should always be non-nullable (have a default value). class Test { var num: Int? = null get() = field ?: 5 // default value if null } The f...
Inlay asked 6/10, 2017 at 13:9

5

Solved

I have a method like this one: public void foo(@Nonnull String value) {...} I would like to write a unit test to make sure foo() throws an NPE when value is null but I can't since the compiler ...

8

Solved

So you can't inherit string. You can't make a non-nullable string. But I want to do this. I want a class, let's call it nString that returns a default value when it would otherwise be null. I have ...
Hansom asked 24/10, 2014 at 18:25

2

Solved

This isn't my first question about nullable reference types as it's been few months I'm experiencing with it. But the more I'm experiencing it, the more I'm confused and the less I see the value ad...
Maleficent asked 26/8, 2020 at 11:1

1

Solved

When specifying a member with a question mark at the end of it's name, the type signature automatically gets extended to include undefined. It's okay to create an instance without this member: int...
Shira asked 10/6, 2020 at 11:10

1

Solved

I have a struct definition which includes, among other things, this field: pub struct Separated<'a, I, T> { ..., // other fields, separated: NonNull<dyn 'a + Iterator<Item = T>&gt...
Collett asked 29/2, 2020 at 20:57

2

I have a DTO which is populated by reading from a DynamoDB table. Say it looks like this currently: public class Item { public string Id { get; set; } // PK so technically cannot be null p...
Dimpledimwit asked 20/12, 2019 at 11:37

2

Solved

I have switched to enable nullable in my project that uses C#8. Now I have the following class: public class Request { public string Type { get; set; } public string Username { get; set; } publ...
Desouza asked 30/12, 2019 at 12:35

1

I have this project: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework>...
Navaho asked 2/12, 2019 at 9:5

1

Solved

The post is specific to C# 8. Let's assume I want to have this method: public static TValue Get<TKey, TValue>( this Dictionary<TKey, TValue> src, TKey key, TValue @default ) =&gt...

1

Solved

RequireSome type from another, very simialar question. This question is similar but it should not be a duplicate since here we want to also remove null as well as undefined from properties. Maybe ...
Taunt asked 15/4, 2019 at 6:30

1

Solved

If I enable nullable reference types, what will be the value of the following string if I declare it like so? string text;
Immesh asked 10/4, 2019 at 8:14

2

Just playing around with C# 8.0 Beta and updating some of my code to use nullable reference types. I have a node style class for a Trie implementation. Each node has a value of type T. The constru...
Hellhole asked 4/4, 2019 at 22:33

1

Solved

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: ...
Steffy asked 20/2, 2019 at 20:44

1

Lombok's @NonNull VS javax.annotation.Nonnull Which one is better to use for method parameters and when? The answer here vaguely compares all annotations but has no inference on which one is best...
Downswing asked 5/2, 2019 at 15:31

3

Solved

How to create non-nullable value types like int, bool, etc. in C#?
Equestrienne asked 15/6, 2011 at 23:4

2

Solved

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 (inste...
Gillian asked 25/7, 2018 at 16:39

© 2022 - 2024 — McMap. All rights reserved.