Is there a way to get a random value depending on the type of field? The exact scenario is to use reflection to get the declared fields of a class. I want to set fake data to the fields that I have.
Field fieldset[] = cls.getDeclaredFields();
for the fld field in the field list, I can get the type using fld.getType()
but I have to set a random value depending on the type at runtime
Random rand = new Random();
random.nextInt()gives me an integer ... but all I want is if there is any method or method like rand(fldtype)that should give me a random field type value
source
share