Generate field of an interface by JavaPoet

247 views Asked by At

Is there any way to generate a field like this:

public static final TypedKey<String> UM_USR = new TypedKey<String>() {};

I didn't find any way to set the type of UM_USR to a generic interface.

1

There are 1 answers

0
Omar Aflak On BEST ANSWER

You need to use a ParameterizedTypeName instead of a simple ClassName :

ParameterizedTypeName paramTypedKey = ParameterizedTypeName.get(ClassName.get(TypedKey.class), ClassName.get(String.class));