You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider the following scenario using the Java API: We declare a new enum-sort E and a new constant C whose sort is E.
If we now try to get the sort of C the API doesn't return an EnumSort but a DatatypeSort. If we now call a method such as getName of the returned sort the application throws a ClassCastException.
So when you call getSort, it calls the native API and that API can only ever return DatatypeSort.
So if you actually need to check whether the sort of a constant was an EnumSort, it is my understanding that you are out of luck.
If you just want to make your code work, it should be enough to cast the result of myConst.getSort() to Sort like so: ((Sort)myConst.getSort()).getName().
Why does Java claim that getSort returns an EnumSort when it doesn't?
This cast here is the reason:
Consider the following scenario using the Java API: We declare a new enum-sort E and a new constant C whose sort is E.
If we now try to get the sort of C the API doesn't return an EnumSort but a DatatypeSort. If we now call a method such as
getName
of the returned sort the application throws aClassCastException
.Here is a minimal example:
Behavior: throws
ClassCastException
Expected: prints "my-enum"
The text was updated successfully, but these errors were encountered: