Is there a way to use the default value on a non-optional parameter when null is passed?

You can define a companion object for your data class and overload its invoke operator to use default values when null is passed: data class Data private constructor( val name: String, val number: Long ) { companion object { operator fun invoke( name: String? = null, number: Long? = null ) = Data( name ?: … Read more

Serious bugs with lifted/nullable conversions from int, allowing conversion from decimal

I’m just replying to the first part of the question to start with. (I suggest that the second part should be a separate question; it’s more likely to be a bug.) There’s only an explicit conversion from decimal to int, but that conversion is being implicitly called in your code. The conversion happens in this … Read more

Can an optional parameter be null in TypeScript?

EDIT: Important Note As Quentin C pointed out in the below comment, the behavior listed here is only when strict null checking is enabled: “strictNullChecks”: true in tsconfig.json. The types null and undefined are handled as separate types. The optional type is special, also allowing arguments to be left out of function calls. 1. Without … Read more

How to use .NET reflection to check for nullable reference type

In .NET 6, the NullabilityInfoContext APIs were added to handle this. See this answer. Prior to this, you need to read the attributes yourself. This appears to work, at least on the types I’ve tested it with. public static bool IsNullable(PropertyInfo property) => IsNullableHelper(property.PropertyType, property.DeclaringType, property.CustomAttributes); public static bool IsNullable(FieldInfo field) => IsNullableHelper(field.FieldType, field.DeclaringType, field.CustomAttributes); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)