-
|
Hello there, while using the following scenario, I am getting an unexpected output (which is unexpected with my current understanding). Is this normal behavior? edit: version: 5.0.2 This call thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Hi @mevlana14! Firstly, I wanted to thank you for supporting Instancio! ❤️ Regarding the error, this is caused by the primitive 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
List.of(
List.of(1, 1, 3, 5),
List.of(1, 2, 3, 5),
List.of(2, 2, 3, 5),
List.of(2, 3, 4, 5),
List.of(3, 3, 4, 5),
List.of(3, 4, 5, 5)
)
)
)
)
.create();This should resolve the class cast error. |
Beta Was this translation helpful? Give feedback.
Hi @mevlana14! Firstly, I wanted to thank you for supporting Instancio! ❤️
Regarding the error, this is caused by the primitive
0inMap.of(0, ...)being converted to anInteger. Since Instancio'sset()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:instead of
To fix it, you can specify the numeric type explicitly: