Hi all,

I encountered something weird about enum value in the object stored in
ignite cache.

for example:

class definition:

public class Application {
    private long id;
    private String name;
    private ApplicationType type;
}

enum definition:

public enum ApplicationType {
    TX {
        @Override
        public boolean isSupported() {
            return true;
        }
    },
    API {
        @Override
        public boolean isSupported() {
            return true;
        }
    };

    public abstract boolean isSupported();
}

then have a cache like:

IgniteCache<Long, Application> cache

When get back the Application instance from cache, the value of the type

property will not equal to the enum value in the enum class, i found their

hash code is different, even though they have same class name.

for example,

Application app = new Application(1L, "app 1", ApplicationType.API);

app.getType() == ApplicationType.API is true

app.getType().getClass().getName() is ApplicationType$2, hash code is 251520863


Application appFound = cache.get(app.getId());

appFound.getType() == Application.API is false

appFound.getType().getClass().getName() is ApplicationType$2, hash
code is 331596257


ApplicationType.API.hashCode() is 251520863


I tried an enum without any method definitions, then no issue. Any
idea about this?


BRs,

David

Reply via email to