nullable

Is there a good Eclipse plugin for checking @Nonnull and @Nullable annotations?

本秂侑毒 提交于 2019-12-05 13:23:21
The checking of the @Nonnull and @Nullable annotations in Eclipse is an early beta . The largest problem is that there it no knowing over the null behavior of the Java API. Are there any other plugins that are better currently? It's now integrated in Eclipse Kepler. I have found that FindBugs works well and is easy to use. FindBugs Plugin Get Eclipse SDK 3.7(or Indigo) Enter this update URL: http://download.eclipse.org/objectteams/updates/contrib Select and install : JDT Null Annotation Checker (Early Access) Object Teams Equinox Integration The largest problem is that there it no knowing over

How scala generic constraints to nullable types work

六月ゝ 毕业季﹏ 提交于 2019-12-05 12:51:03
问题 I've tried two ways to constrain a generic type parameter to a nullable type, but both seem to have some unexpected problems. First attempt (using T <: AnyRef): scala> def testAnyRefConstraint[T <: AnyRef](option:Option[T]):T = { | //without the cast, fails with compiler error: | // "found: Null(null) required: T" | option getOrElse null.asInstanceOf[T] | } testAnyRefConstraint: [T <: AnyRef](Option[T])T scala> testAnyRefConstraint(Some("")) res0: java.lang.String = scala>

MySQL ON DUPLICATE KEY UPDATE with nullable column in unique key

倾然丶 夕夏残阳落幕 提交于 2019-12-05 12:26:03
问题 Our MySQL web analytics database contains a summary table which is updated throughout the day as new activity is imported. We use ON DUPLICATE KEY UPDATE in order that the summarization overwrites earlier calculations, but are having difficulty because one of the columns in the summary table's UNIQUE KEY is an optional FK, and contains NULL values. These NULLs are intended to mean "not present, and all such cases are equivalent". Of course, MySQL usually treats NULLs as meaning "unknown, and

Convert decimal? to double?

我与影子孤独终老i 提交于 2019-12-05 12:24:44
问题 I am wondering what would be the best way (in the sense of safer and succinct) to convert from one nullable type to another "compatible" nullable type. Specifically, converting from decimal? to double? can be done using: public double? ConvertToNullableDouble(decimal? source) { return source.HasValue ? Convert.ToDouble(source) : (double?) null; } Is there any better way to do this? Maybe leveraging a standard conversion? 回答1: Built in casts for the win! Just tested this in VS2012 and VS2010:

Do XML parsers tell the difference between xsi:nil=“true” and omitted elements?

自古美人都是妖i 提交于 2019-12-05 11:14:29
Are XML parsers/deserializers in general able to tell the difference between nillable elements explicitly set to null and optional elements that are left out ? Assume that we have the following complex type: <complexType name="NiceType"> <sequence> <element name="niceElem" nillable="true" type="int" minOccurs="0" /> </sequence> </complexType> Element explicitly set to null (example 1): <niceType> <niceElem xsi:nil="true"/> </niceType> Element omitted (example 2): <niceType> </niceType> Would parsers in general, such as JAX-B implementations or .NET alikes such as the XML module of WCF, be able

Can we ensure nullability of `+ (nonnull instancetype)sharedInstance;`?

与世无争的帅哥 提交于 2019-12-05 09:37:10
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; dispatch_once(&onceToken, ^ { sharedInstance = [[self alloc] init]; }); return sharedInstance; } But now I want to declare it as nonnull , if possible: + (nonnull instancetype)sharedInstance; Unfortunately, init returns a nullable instancetype value. Should I add an NSAssert or something after calling init ? I noticed that some people even document nonnull

The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable<T>'

我的梦境 提交于 2019-12-05 08:45:54
public virtual int Fill(DataSetservices.Jobs_detailsDataTable dataTable, global::System.Nullable<global::System.String> fromdate, global::System.Nullable<global::System.DateTime> todate) I wrote above code in dataset.xsd in C#, but it is throwing an error: Error 1 The type 'string' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'System.Nullable' Suggest me how to use string because i want to use string and nothing else string is already nullable, because it's a reference type. You don't need to wrap it in Nullable in order to have a null

Cast a null into something?

江枫思渺然 提交于 2019-12-05 08:35:21
I had this interesting discussion today with a colleague. We were debating two pieces of code in C#. Code Snippet 1: if(!reader.IsDBNull(2)) { long? variable1 = reader.GetInt64(2) } Code Snippet 2: long variable1 = reader.IsDBNull(2) ? (long?) null : reader.GetInt64(2) Question is: is it a good practice to cast null into a nullable long? Or would you rather use the traditional if statement to avoid casting null to nullable long. The expressions (type?)null , default(type?) and new Nullable<type>() end up being compiled into the same opcodes: long? x = (long?)null; long? y = default(long?);

What is 'long?' data type?

左心房为你撑大大i 提交于 2019-12-05 08:26:19
问题 I am going over some code written by another developer and am not sure what long? means: protected string AccountToLogin(long? id) { string loginName = ""; if (id.HasValue) { try {.... 回答1: long is the same as Int64 long data type The ? means it is nullable A nullable type can represent the normal range of values for its underlying value type, plus an additional null value Nullable Types Nullable example: int? num = null; if (num.HasValue == true) { System.Console.WriteLine("num = " + num

In C#, what is the `?` in the type `DateTime?` [duplicate]

半腔热情 提交于 2019-12-05 08:02:19
This question already has answers here : What does “DateTime?” mean in C#? (6 answers) Closed 6 years ago . I just ran across some code while working with System.DirectoryServices.AccountManagement public DateTime? LastLogon { get; } What is the ? after the DateTime for. I found a reference for the ?? Operator (C# Reference) , but it's not the same thing. (280Z28: Here is the correct link for Using Nullable Types .) The ? makes it a nullable type (it's shorthand for the Nullable<T> Structure and is applicable to all value types). Nullable Types (C#) Note: The ?? you linked to is the null