var blks = ReflectionHelper.getClasses("PACKAGE_NAME");
var blockRta = RuntimeTypeAdapterFactory.of(Block.class);
for (var c : blks) {
if (Block.class.isAssignableFrom(c)) {
blockRta.registerSubtype(c);
}
}
I got Warning:(31, 46) Unchecked assignment: 'java.lang.Class' to 'java.lang.Class<? extends PACKAGE_NAME.Block>'
warning on the line blockRta.registerSubtype(c);
, but I can't figure out how to fix that without supressing it.
ReflectionHelper.getClasses
is a static method to get all the classes in that package name, and its return type is Class[]
. Block
is an interface. RuntimeTypeAdapterFactory
is a class in gson extra, and its source code can be viewed here.
Aucun commentaire:
Enregistrer un commentaire