You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can simple do the followings to recreate the issue:
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ExampleClass {
private Optional<String> a;
private Optional<String> b;
}
ExampleClass e1 = easyRandom.nextObject(ExampleClass.class);
ExampleClass e2 = new ExampleClass(Optional.of("asd"), Optional.of("asd"));
System.out.println(e1);
// note that printed fields are Optional[Object]
ExampleClass(a=Optional[java.lang.Object@7675f6], b=Optional[java.lang.Object@3117145])
System.out.println(e2);
ExampleClass(a=Optional[asd], b=Optional[asd])
e2.getA().ifPresent(System.out::println);
// Prints the fields value successfully if A is Some
e1.getA().ifPresent(System.out::println);
class java.lang.Object cannot be cast to class java.lang.String (java.lang.Object and java.lang.String are in module java.base of loader 'bootstrap')
The text was updated successfully, but these errors were encountered:
As I explained in gitter https://gitter.im/j-easy/easy-random?at=5eb800d25cd4fe50a3ffea5f Optional fields generated by easy-random can not be casted to actual value of T.
You can simple do the followings to recreate the issue:
The text was updated successfully, but these errors were encountered: