non-nullable

Getter and @Nonnull

半世苍凉 提交于 2019-12-21 12:04:23
问题 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 javax.annotation.ParametersAreNonnullByDefault; test.java package test; public class Test { public static void main( final String[ ] args ) { System.out.println( new Test( "a" ).getS( ) ); } private final String s; public Test( final String s ) { this.s = s; } public String getS( )

What would we do without NULL?

陌路散爱 提交于 2019-12-20 09:22:37
问题 I once read that having nullable types is an absolute evil. I believe it was in an article written by the very person who created them(in Ada?) I believe this is the article Anyway, so what if by default a language like C# used non-nullable types? How would you replace some of the common idioms in C# or Ruby or any other common language where null is an acceptable value? 回答1: Instead of outright declaring that nullable types are evil, I would posit: most languages graft nullability onto

Why is null not allowed for DateTime in C#?

蹲街弑〆低调 提交于 2019-12-18 13:53:02
问题 Why it is not allowed to assign null to a DateTime in C#? How has this been implemented? And can this feature be used to make your own classes non-nullable? Example: string stringTest = null; // Okay DateTime dateTimeTest = null; // Compile error I know that I can use DateTime? in C# 2.0 to allow null to be assigned to dateTimeTest and that I could use Jon Skeet's NonNullable class on my string to get a run time error on the assignment of stringTest. I'm just wondering why the two types

Non-nullable reference types

折月煮酒 提交于 2019-12-18 04:43:10
问题 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? What would you do about this: class Foo { Bar? b; Bar b2; Foo() { b.DoSomething(); //valid, but will cause exception b2.DoSomething(); //? } } 回答1: My current language design philosophy is that nullability should be something a programmer is forced to ask for, not given by default on reference

How can I get close to non-nullable reference types in C# today?

守給你的承諾、 提交于 2019-12-17 19:09:41
问题 I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack. However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo& ). The compiler makes this work by adding modreq(IsImplicitlyDereferenced) to the argument. Trying to call such a function from C# results in: '<FunctionName>' is not supported by the language Is there

Why @Nonnull annotation checked at runtime?

别说谁变了你拦得住时间么 提交于 2019-12-17 17:53:24
问题 I have a function with following signature public static String myFunction(@Nonnull String param) When I call it with param as null, I get the following exception: Caused by: java.lang.IllegalArgumentException: Argument for @Nonnull parameter 'param' of com/MyClass.myFunction must not be null at com.MyClass.$$$reportNull$$$0(MyClass.java) javax.annotation.Nonnull supposed not to be checked at runtime. Who actually throws the exception and why? P.S. I run Tomcat server in debug mode from

Best explanation for languages without null

喜欢而已 提交于 2019-12-17 04:09:40
问题 Every so often when programmers are complaining about null errors/exceptions someone asks what we do without null. I have some basic idea of the coolness of option types, but I don't have the knowledge or languages skill to best express it. What is a great explanation of the following written in a way approachable to the average programmer that we could point that person towards? The undesirability of having references/pointers be nullable by default How option types work including strategies

Best explanation for languages without null

有些话、适合烂在心里 提交于 2019-12-17 04:09:18
问题 Every so often when programmers are complaining about null errors/exceptions someone asks what we do without null. I have some basic idea of the coolness of option types, but I don't have the knowledge or languages skill to best express it. What is a great explanation of the following written in a way approachable to the average programmer that we could point that person towards? The undesirability of having references/pointers be nullable by default How option types work including strategies

Java generic with return type that has @NonNull with Collections

眉间皱痕 提交于 2019-12-11 02:58:27
问题 I want to implement a generic function in Java8, that verifies that a collection has no null members and returns a type with @NonNull annotation. input type: T extends Collection, where T+U are nullable. result type: @NonNull T, with @NonNull U For array this would look like this: public static <T> @NonNull T @NonNull[] arrayHasNoNullMember( @Nullable T @Nullable[] value) { But for the collection case, i don't know how to define that the result type is the same as the input type, but has the

Nullable “scalar navigation properties” in EF 4.0: Mapping a non-nullable column from a separate database table to a nullable scalar entity property?

核能气质少年 提交于 2019-12-10 22:06:27
问题 Using Entity Framework version 4.0 (or any other version that is compatible with .NET 4.0), I want to map this existing relational database schema: to this logical object model: which I have tried setting up as follows: (I hope the German captions won't be too disorienting.) Entity Framework gives me this error: Error 3031: Problem in mapping fragments …: Non-nullable column FooBs.B in table FooBs is mapped to a nullable entity property. In the logical model, B ought to be nullable. However,