nullable

Kotlin: eliminate nulls from a List (or other functional transformation)

假如想象 提交于 2019-12-30 16:18:33
问题 Problem What is the idiomatic way of working around this limitation of the null-safety in the Kotlin type system? val strs1:List<String?> = listOf("hello", null, "world") // ERROR: Type Inference Failed: Expected Type Mismatch: // required: List<String> // round: List<String?> val strs2:List<String> = strs1.filter { it != null } This question is not just about eliminating nulls, but also to make the type system recognize that the nulls are removed from the collection by the transformation. I

Hibernate default joining for nullable many-to-one

故事扮演 提交于 2019-12-30 08:04:28
问题 I have a hibernate mapping like this in a ProductDfn class @ManyToOne( fetch = FetchType.LAZY, optional = true ) @JoinColumn( name = "productTypeFk", nullable = true ) public ProductType getProductType() { return productType; } Note that the relationship is defined as optional (and the column is nullable). When doing HQL something like this select p.name as col1, p.productType.name as col2 from ProductDfn p An inner join is used to join ProductDfn to ProductType as hibernate generates the

QuickWatch is not work correctly for show “.ToString()” of Nullable properties

旧城冷巷雨未停 提交于 2019-12-30 04:03:06
问题 I have a nullable integer property in vb.net. This property in code has correct value, but in the QuickWatch always display 1 , unless I initial it by a value then display a six digitalis numbers. My codes is: Public Property MyNumber As Integer? MyNumber = 6546 MessageBox.Show(MyNumber.ToString()) And for nullable double property in QuickWatch always display 4/94065645841247E-324 . I test this on .Net 4 & 4.5 on visual studio 2010 & 2013 and get same result. However C# hasn't this problem

svcutil.exe - Proxy generated not allowing for nullable fields

我与影子孤独终老i 提交于 2019-12-30 03:25:24
问题 I am trying to consume a web service specified using WSDL by creating a WCF proxy using svcutil.exe, but the WSDL specifies that some of the operations have parameters that are optional (minOccurs="0"), for example: <xs:element minOccurs="0" maxOccurs="1" name="meetingId" type="xs:int" /> Unfortunately, the generated proxy does not allow me to not specify the values (the parameters are not nullable), and there are no "specified" fields as part of the call to instruct the proxy that no value

Why is a Nullable<T> not a valid Custom Attribute Parameter when T is?

拜拜、爱过 提交于 2019-12-30 02:36:06
问题 If I have an enum like this public enum Hungry { Somewhat, Very, CouldEatMySocks } and a custom attribute like this public class HungerAttribute : Attribute { public Hungry HungerLevel { get; set; } public Hungry? NullableHungerLevel { get; set; } } I can do this [Hunger(HungerLevel = Hungry.CouldEatMySocks)] public class Thing1 but I can't do this [Hunger(NullableHungerLevel = Hungry.CouldEatMySocks)] public class Thing2 It generates an error that says "'NullableHungerLevel' is not a valid

Why does passing $null to a parameter with AllowNull() result in an error?

只谈情不闲聊 提交于 2019-12-29 09:27:07
问题 Consider the following code: function Test { [CmdletBinding()] param ( [parameter(Mandatory=$true)] [AllowNull()] [String] $ComputerName ) process{} } Test -ComputerName $null Based on the official documentation for AllowNull I was expecting that $ComputerName could either be [string] or $null . However, running the above code results in the following error: [14,24: Test] Cannot bind argument to parameter 'ComputerName' because it is an empty string. Why doesn't passing $null for

Why is Nullable<T> nullable? Why it cannot be reproduced?

余生长醉 提交于 2019-12-29 07:55:10
问题 When I write Nullable<Nullable<DateTime>> test = null; I get a compilation error: The type 'System.Datetime?' must be a non-nullable value type in order to use it as a paramreter 'T' in the generic type or method 'System.Nullable<T>' But Nullable<T> is a struct so it's supposed to be non-nullable. So I tried to create this struct : public struct Foo<T> where T : struct { private T value; public Foo(T value) { this.value = value; } public static explicit operator Foo<T>(T? value) { return new

How does the NotNull trait work in 2.8 and does anyone actually use it?

谁说胖子不能爱 提交于 2019-12-29 06:01:02
问题 trait NotNull {} I've been trying to see how this trait can guarantee that something is not null and I can't figure it out: def main(args: Array[String]) { val i = List(1, 2) foo(i) //(*) } def foo(a: Any) = println(a.hashCode) def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract def foo(a: Any with NotNull) = println(a.hashCode) //compile error: type mismatch at (*) And: val i = new Object with NotNull //compile-error illegal inheritance There is

How does the NotNull trait work in 2.8 and does anyone actually use it?

谁都会走 提交于 2019-12-29 06:00:26
问题 trait NotNull {} I've been trying to see how this trait can guarantee that something is not null and I can't figure it out: def main(args: Array[String]) { val i = List(1, 2) foo(i) //(*) } def foo(a: Any) = println(a.hashCode) def foo(@NotNull a: Any) = println(a.hashCode) //compile error: trait NotNull is abstract def foo(a: Any with NotNull) = println(a.hashCode) //compile error: type mismatch at (*) And: val i = new Object with NotNull //compile-error illegal inheritance There is

Why should I specify @Column( nullable = false )?

主宰稳场 提交于 2019-12-29 03:32:08
问题 I have an entity annotated with @Entity . If I am responsible for creating the CREATE TABLE scripts why should I specify @Column( nullable = false ) when I can create a column in the database with the NOT NULL keywords? Is there any example that shows the benefits of using this property in a field? 回答1: Better error messages and error handling, especially if you also add the JSR303 @NotNull annotation. If you create the column as NOT NULL but don't tell JPA it's not null, JPA will assume that