I'm working on a project to translate a c# project to Java. I have the following Get/Set block in C#
public Unit[] Units
{
get
{
Unit[] units_aux = new Unit[this.list_units.Count];
this.list_units.CopyTo(units_aux);
return units_aux;
}
set
{
if (value == null) return;
Unit[] units_aux = (Unit[])value;
this.list_units.Clear();
foreach (Unit u in units_aux)
this.lista_units.Add(u);
}
}
I want to translate this to Java, but I have not been successful in translating it with no syntax errors. I'm very new to Java, so maybe this is a basic question, but i haven't found any information on how to do this that won't produce errors.
Thanks for your help
You'd basically have to convert it to a pair of methods:
public Unit[] getUnits() {
// Method body
}
public void setUnits(Unit[] value) {
// Method body
}
Java doesn't have properties at a language level - the above is basically just a (very common) convention.
I should note, by the way, that this C# code really isn't terribly nice:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With