Giter Club home page Giter Club logo

Comments (6)

pfusik avatar pfusik commented on September 23, 2024 1

Thank you for this question!

This decision was made long time ago, when Android was avoiding Java enums.
It looks like Android's reasons are now obsolete so I'm going to change cito to emit Java enums.

from fut.

pfusik avatar pfusik commented on September 23, 2024

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
}

?

from fut.

pfusik avatar pfusik commented on September 23, 2024
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;
	}
}

?

from fut.

pfusik avatar pfusik commented on September 23, 2024
Ć Java
f1 == f2 f1.equals(f2)
~f EnumSet.complementOf(f)
f1 &= f2; f1 = EnumSet.copyOf(f1); f1.retainAll(f2);
f1 |= f2; f1 = EnumSet.copyOf(f1); f1.addAll(f2);
f1.HasFlag(f2) f1.containsAll(f2)
f1 ^ f2 (symmetric difference) ???

from fut.

crmorello avatar crmorello commented on September 23, 2024

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

from fut.

pfusik avatar pfusik commented on September 23, 2024

EnumSet is problematic. Assigning (integer or other enum) values to Java enum is problematic.
For now, I'm going to emit Java enums only for non-flags enums with no assigned values. Other enums will remain interfaces with int constants.

from fut.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.