0
} else if (fieldType.equals(Float.TYPE)) {
  return random.nextFloat(); //catches primitive
} else if (fieldType.equals(Boolean.TYPE)) {
  return random.nextBoolean();
} else if (Number.class.isAssignableFrom(fieldType)) {
  return random.nextInt(Byte.MAX_VALUE) + 1; //catches Float

我怎样才能在同一个地方捕捉原始和对象?

(哪里Class<?> fieldType

4

1 回答 1

4

Compare with Float.TYPE and Float.class.

First is the primitive, latter is the wrapper.

I.e. if(fieldType.equals(Float.class) || fieldType.equals(Float.TYPE))

于 2013-08-06T14:48:40.373 回答