I just wonder that can we specify the orders of fields of a class?
I have a class (let's say subClass) which extends another class (superCalss).
public class SuperClass {
Object superClassFiled1;
Object superClassFiled2;
Object superClassFiled3;
...
}
public class SubClasss extends SuperClass {
Object subClassField1;
Object subClassField2;
}
When I print out the subClass, subClass's fields coma first but I nee a special order like that:
{
superClassFiled1 : "someValue",
subClassField1 : "someValue",
subClassField2 : "someValue",
superClassFiled2 : "someValue",
superClassFiled3 : "someValue",
...
}
I use subClass.getFields()
to get fields.
Is there any way to order them?
Note: I want to order them before callig subClass.getFields()
.
I have tried many ways and decided to create a new class which duplicates the fields of the main class. So I ordered the fields in the class.