-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enum generated as Java interface #81
Comments
Thank you for this question! This decision was made long time ago, when Android was avoiding Java enums. |
How to transpile flags? I'm aware of EnumSet, but how would you transpile: public enum* Inventory
{
None = 0,
Gun = 1,
Knife = 2,
Weapons = Gun | Knife,
Key = 4
} ? |
import java.util.EnumSet;
public enum Inventory
{
_GUN,
_KNIFE,
_KEY;
public static final EnumSet<Inventory> NONE = EnumSet.noneOf(Inventory.class);
public static final EnumSet<Inventory> GUN = EnumSet.of(_GUN);
public static final EnumSet<Inventory> KNIFE = EnumSet.of(_KNIFE);
public static final EnumSet<Inventory> WEAPONS = EnumSet.of(_GUN, _KNIFE);
public static final EnumSet<Inventory> KEY = EnumSet.of(_KEY);
/// The `&` operator.
public static EnumSet<Inventory> retaining(EnumSet<Inventory> a, EnumSet<Inventory> b)
{
EnumSet<Inventory> result = EnumSet.copyOf(a);
result.retainAll(b);
return result;
}
/// The `|` operator.
public static EnumSet<Inventory> adding(EnumSet<Inventory> a, EnumSet<Inventory> b)
{
EnumSet<Inventory> result = EnumSet.copyOf(a);
result.addAll(b);
return result;
}
} ? |
|
Ah nice, thanks for taking a look into this. The EnumSet solution looks good to me, though I don't write Java often so I'm not an authority on the matter. I think for symmetric difference most people generally rely on a library as there is no built in. There is two different implementations here to get an idea: https://rosettacode.org/wiki/Symmetric_difference#Java |
|
Just curious if there is a particular reason why Cito enums are generated as separate Java interfaces?
This:
Generates a separate
TestEnum.java
file that contains:I would have expected the following since the syntax is almost identical in this case
The text was updated successfully, but these errors were encountered: