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
Implement class JEnum<E>, porting of the Java class java.lang.Enum<E>.
This is the common base class of all Java language enumeration types. More information about enums, including descriptions of the implicitly declared methods synthesized by the compiler, can be found in section 8.9 of The Java™ Language Specification.
E - The enum type subclass
In Java the Enum class is never used directly, but it's internally instantiated when used the enum keyword. Moreover, Enum class represents only an enum constant and not an enum type, that is represented by a Class object, in fact an enumeration could have members or methods.
The Mobile enumeration type will have three static members for its three constants (that are themselves instances of "class" Mobile) and also implicit methods values() and valueOf(String).
Enum constants could be classes too:
enumOperation {
PLUS {
doubleeval(doublex, doubley) { returnx + y; }
},
MINUS {
doubleeval(doublex, doubley) { returnx - y; }
},
TIMES {
doubleeval(doublex, doubley) { returnx * y; }
},
DIVIDED_BY {
doubleeval(doublex, doubley) { returnx / y; }
};
// Each constant supports an arithmetic operationabstractdoubleeval(doublex, doubley);
publicstaticvoidmain(Stringargs[]) {
doublex = Double.parseDouble(args[0]);
doubley = Double.parseDouble(args[1]);
for (Operationop : Operation.values())
System.out.println(x + " " + op + " " + y + " = " + op.eval(x, y));
}
}
/* outputjava Operation 2.0 4.02.0 PLUS 4.0 = 6.02.0 MINUS 4.0 = -2.02.0 TIMES 4.0 = 8.02.0 DIVIDED_BY 4.0 = 0.5*/
What should be the corresponding code in our framework?
Implement class
JEnum<E>
, porting of the Java classjava.lang.Enum<E>
.Expected Behavior
extends
JObject
classimplements
JComparable<T>
interfaceimplements
JSerializable
interfaceprotected 2-params constructor
constructor(name: JString, ordinal: Jint)
valueOf<T extends Enum<T>>(enumType: JClass<T>, name: JString): T
compareTo(E o): Jint
equals(other: JObject): Jboolean
hashCode(): Jint
name(): JString
ordinal(): Jint
toString(): JString
clone(): JObject
Do it later
getDeclaringClass(): JClass<E>
finalize(): void
The text was updated successfully, but these errors were encountered: