Skip to content

How to correctly handle null values passed as method argumets? #452

Answered by uniqx
uniqx asked this question in Q&A
Discussion options

You must be logged in to vote

I ended up unwrapping the JString variable into and Option:

    let myValue: Option<String> = match env.get_string(&myValue) {
        Ok(v) => Some(v.to_string_lossy().into_owned()),
        Err(_) => None,
    };

So when my java method gets called with the String parameter set to null: (new MyClass()).myMethod(null) it'll convert to Option::None on the rust side.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@argv-minus-one
Comment options

Answer selected by uniqx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants