Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value was not returned when decode type and encode type mismatch #63

Closed
jianzhongli opened this issue Sep 30, 2018 · 1 comment

Comments

@jianzhongli
Copy link

jianzhongli commented Sep 30, 2018

If we write some data of type A and read it as type B with the same key, unexpected value will be returned. For example:

MMKV kv = MMKV.mmkvWithID(mmapID, MMKV.SINGLE_PROCESS_MODE, cryptKey);
kv.encode("bool", true);
int val = kv.decodeInt("bool", 100);
System.out.println("decode int with key bool: " + val);

The terminal will print decode int with key bool: 1. That is kind of misleading since we never store any int value with key "bool", meanwhile there was no error or exception thrown when we are doing this implicit casting.

Is this an intentional design?

@lingol
Copy link
Collaborator

lingol commented Sep 30, 2018

Yes. MMKV does type erasure while storing values. That means type mismatch detection is impossible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants