I will like to know if there is a way to do the second or third return statement in Java
Example using C#:
I have this class with properties
class Properties
{
public int ResponseCode { get; set; }
public string ResponseMessage { get; set; }
public string Name { get; set; }
public string Academics { get; set; }
}
I did it like this at the beginning:
public static Properties CreateStudentFirstWay()
{
Properties properties = new Properties();
properties.Name = "Michael";
properties.Academics = "Information";
properties.ResponseCode = 0000;
properties.ResponseMessage = "Created";
return properties;
}
I use this from time to time
public static Properties CreateStudentSecondWay()
{
Properties properties = new Properties()
{
Name = "Michael",
Academics = "Information",
ResponseCode = 0000,
ResponseMessage = "Created"
};
return properties;
}
And recently I have been doing it like this
public static Properties CreateStudentThirdWay()
{
return new Properties()
{
Name = "Michael",
Academics = "Information",
ResponseCode = 0000,
ResponseMessage = "Created"
};
}
We are able to do the last one in C# without a constructor, without a builder or even without the need to populate all the properties in the class.
Is there a way to accomplished this in Java without the need of a constructor or the builder?
Thanks!