-
Notifications
You must be signed in to change notification settings - Fork 1
Bio Enum Inheritance
Bio Enums can be extended since they are classes.
package com.linkedlogics.bio.test.car;
@BioEnumObj
public class EngineType extends BioEnum {
public EngineType(int ordinal, String name) {
super(ordinal, name);
}
public final static EngineType VEE = new EngineType(0, "vee");
public final static EngineType INLINE = new EngineType(1, "inline");
public final static EngineType ROTARY = new EngineType(2, "rotary");
}
When we export dictionary to XML, we will get.
<?xml version="1.0" encoding="UTF-8"?>
<dictionary code="0">
<enum type="EngineType" code="5092" version="0" class="com.linkedlogics.bio.test.car.EngineType">
<value code="0" name="vee"/>
<value code="1" name="inline"/>
<value code="2" name="rotary"/>
</enum>
</dictionary>
Now we extend and add new enum types as following:
package com.linkedlogics.bio.test.car.ext;
@BioEnumObj
public class EngineType extends com.linkedlogics.bio.test.car.EngineType {
public EngineType(int ordinal, String name) {
super(ordinal, name);
}
public final static EngineType ELECTRICAL = new EngineType(3, "electrical");
}
then we get new dictionary as following:
<?xml version="1.0" encoding="UTF-8"?>
<dictionary code="0">
<enum type="EngineType" code="5092" version="0" class="com.linkedlogics.bio.test.car.EngineType">
<value code="0" name="vee"/>
<value code="1" name="inline"/>
<value code="2" name="rotary"/>
<value code="3" name="electrical"/>
</enum>
</dictionary>
Note that class for hasn't changed to newer one. This is for resolving ambiguities. Let assume we have an array of enums and first item is instance of com.linkedlogics.bio.test.car.EngineType
and second item com.linkedlogics.bio.test.car.ext.EngineType
. If our enum array type will be com.linkedlogics.bio.test.car.ext.EngineType[]
then first enum value will not fit due to improper class and will throw java.lang.ArrayStoreException
exception. But if we keep super class both values will fit in.
Note that changing class name to for example PlaneEngineType
is NOT recommended because all tag types will still use EngineType
.