Anyone saw this error when trying to run property-...
# kotest
k
Anyone saw this error when trying to run property-based test using generic types?
Copy code
java.lang.ClassCastException: java.base/sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.base/java.lang.Class
s
Can you post up code that causes that ?
k
Copy code
forAll<Graph<String>> { graph ->
    graph.isNotEmpty()
}
s
Ok, seems like it doesn't like higher kinded types
k
I guess the error has to do with the fact that execution ends up in an inline function with a reified type parameter, yes...
The type parameter of Graph type constructor gets erased, so the the runtime has no means to figure out how to instantiate instances of requested type
s
right
we can fix the exception
k
it's a bit obscure, yes
s
but it won't work anyway, as the Graph type isn't built in, so it has no way of knowing which arb to use. You would need to pass in the gen.
k
yep, thanks for help! I will try to
s
so something like
forAll(Graph.strings()) { graph -> }
the
forAll<A, B, ... N>
syntax is shorthand for that