Skip to content
Discussion options

You must be logged in to vote

Hi @mevlana14! Firstly, I wanted to thank you for supporting Instancio! ❤️

Regarding the error, this is caused by the primitive 0 in Map.of(0, ...) being converted to an Integer. Since Instancio's set() method accepts any object, there's no type information available to the compiler to give you an error. As a result, the field gets assigned:

TreeMap<Integer, List<List<Integer>>>

instead of

TreeMap<Long, List<List<Integer>>>

To fix it, you can specify the numeric type explicitly:

Foo foo = Instancio.of(Foo.class)
                .set(field(Foo::bar), new TreeMap<>(
                                Map.of(
                                        0L,  // 0L instead of 0

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mevlana14
Comment options

mevlana14 Mar 5, 2025
Author Sponsor

@armandino
Comment options

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