Null-safe invocation of Enum.compareTo()?
I look for an utilities class or self-implementation to invoke Enum.compareTo()
in a null-safe manner.
Does anyone know such a class or how to implement it? I have a few enumerations written here and I COULD write one for each one. But I guess there might be a more intelligent and flexible way to do this.
The background here is that I have a public default constructor for the #JPA here and an other constructor that beside some other class fields sets this enumeration. Still I need to compare both instances ("empty" one and one with set values) in a null-safe manner. If I try to implement it without the null-check, it throws the all-famous #NPE at me and a unit-test fails.
PS: Is there a #Java group/forum like !java
available somewhere?
Enum.compareTo()
by implementing a static method accepting Enum<?>
as types) and then checking both on equality (==
) and null
each. If none of them is null
, the method Enum.compareTo()
can be safely invoked.
Blackbird reshared this.
Sylvia J likes this.
Pascal
in reply to Roland Häder🇩🇪 • • •- bis auf die Sache mit der rakete vielleicht ^^