Issues related to enum and class inheritance Enum

problem description

I use enum to represent an enumerated class
in addition, I use XXX extends Enum to represent an enumerated class

public final class ApprovalStatusEnum extends Enum {
    private static final long serialVersionUID = -502007467073163619L;

    private String label;

    public static final ApprovalStatusEnum PASS = new ApprovalStatusEnum("PASS", "");

    public static final ApprovalStatusEnum REJECT = new ApprovalStatusEnum("REJECT", "");

    public static final ApprovalStatusEnum WAIT = new ApprovalStatusEnum("WAIT", "");

    public ApprovalStatusEnum(String name, String label) {
        super(name);
        this.label = label;

    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }
}
public enum ApprovalStatusEnum1 {

    PASS("PASS", ""),

    REJECT("REJECT", ""),

    WAIT("WAIT", "");

    private String name ;

    private String label;

    ApprovalStatusEnum1(String name, String label) {
        this.name = name;
        this.label = label;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }
}

enum decompiled and found to inherit Enum, so the two enumerated classes should be the same.

then I wrote this method (the method receives a Class): inherited from Enum

    public static <T extends Enum> T test(Class<T> clazz){
//      xxxxxxxxxxxxx
        return null;
    }

then test it with these two classes

clipboard.png

found an error? Why is that? Obviously both classes inherit Enum. It should all be compiled and passed. Ask for advice.

is a little confused, which boss can explain it?

Mar.29,2021

what you want is that they are both the same?
1. Is the inheritance Enum you specify java.lang.Enum? So the Enum you specified at the beginning is a class object instead of java.lang.Enum
2. Your test method should be changed

.
public class TestEnum {
    public static <T extends Enum> T test(Class<T> clazz){
//      xxxxxxxxxxxxx
        return null;
    }

    public static <T extends java.lang.Enum> T testLnag(Class<T> clazz){
//      xxxxxxxxxxxxx
        return null;
    }

    public static void main(String[] args) {
        test(ApprovalStatusEnum.class);
        testLnag(ApprovalStatusEnum1.class);
    }
}

3. If you want the same thing, ApprovalStatusEnum should also be a java.lang.Enum

public enum ApprovalStatusEnum{
    ;
    private static final long serialVersionUID = -502007467073163619L;

    private String label;

    private String name;

    ApprovalStatusEnum(String name, String label) {
        this.name = name;
        this.label = label;

    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }
}

Test class

public class TestEnum {
    public static <T extends Enum> T test(Class<T> clazz){
//      xxxxxxxxxxxxx
        return null;
    }

    public static <T extends java.lang.Enum> T testLnag(Class<T> clazz){
//      xxxxxxxxxxxxx
        return null;
    }

    public static void main(String[] args) {
        testLnag(ApprovalStatusEnum.class);
        testLnag(ApprovalStatusEnum1.class);
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c392-e847.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c392-e847.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?