Closed HideNameUser closed 1 week ago
Noted.
I have taken a deeper look into this issue. It is more complicated than I thought.
The problem is that the Android interface, which many of you OHOS developers are familiar with, returns 0/false
when a primitive type of value does not exist. If we declared the interface as
public decodeBool(key: string, defaultValue?: boolean): boolean | undefined;
By default, it will return undefined
on non-exist values, even if you have not passed undefined
as the defaultValue
. This behavior doesn't agree with the Andoird/Java interface many of you have been familiar with.
Now, how about we declare it as:
public decodeBool(key: string, defaultValue?: boolean = false): boolean | undefined;
The problem is that it won't compile.
Maybe we have to drop the undefined default value.
I've decided that undefined
will be returned on non-existent values unless a specific defaultValue
is passed in.
It's fixed in 1.3.6-beta2 on OHPM.
let defaultValue:number | undefined = undefined MMKV.decodeDouble("KEY_NOT_FUND", defaultValue) 返回的结果为0,不是想要的默认值undefined 标题中提到的int、float也是同样的 boolean类型返回默认值为false,也无法返回undefined。 返回undefined能知道是没有存过这个值。