Skip to content

Assert that all fields that are primitive type or collection of primitive type #440

@GeeJoe

Description

@GeeJoe

I want to make sure that all fields of a Class should be primitive type or collection of primitive type:

class MyClass {
 String a;
 int b;
 float c;
 int[] d;
 List<String>;
}

How can I achieve that?
I've tried the following code to make part of it works

javaField.rawType.isPrimitive // check whether the field is primitive type
javaField.rawType.simpleName == "String" // check whether it's String

But how can I check whether the field is an Array of primitive type, such as int[] byte[], or a List of primitive type, such as List<String>, etc?

In other words:

  • How can I know the generic type inside a List<T>?
  • How to describe an Array of a primitive type?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions