getEnumType static method

Class getEnumType(
  1. Class? targetType
)

Resolves the enum class from the given targetType.

  • If targetType is an enum, returns it directly.
  • Otherwise, searches the superclass chain for an enum type.

Throws an IllegalArgumentException if no enum type is found.

🔧 Example

Class enumType = ConversionUtils.getEnumType(Class<MyEnum>());

Implementation

static Class getEnumType(Class? targetType) {
	while (targetType != null && !targetType.isEnum()) {
		targetType = targetType.getSuperClass();
	}
	assert(targetType != null, "The target type ${targetType?.getName()} does not refer to an enum");
	return targetType!;
}