0

Is there a way to resolve the code? -

for (FieldInfo fieldInfo : info.getResult()) {
    result.addField(FieldSpec.builder(ClassName.bestGuess(fieldInfo.getClazz()),fieldInfo.getName())
          .addModifiers(Modifier.PRIVATE)
          .build()
    );
}

when fieldInfo.getClazz() returns "int","float", the code would throw an error as

java.lang.IllegalArgumentException: couldn't make a guess for int

Naman
  • 27,789
  • 26
  • 218
  • 353
Jude95
  • 37
  • 3
  • Can you share what `info` here is and confirm the `FieldInfo` is `sun.reflect.FieldInfo`? – Naman Jan 29 '17 at 15:55

1 Answers1

0

Java’s type system has lots of kinds of types: classes, arrays, primitives, parameterized types, etc. The method you’re using assumes the caller wants a ClassName and not a primitive. Use TypeName.INT for that.

Jesse Wilson
  • 39,078
  • 8
  • 121
  • 128