Reputation: 21
I am converting methods from my C# selenium framework into a Java equivalent All is good except a particular method shown below
public class BusinessUserDetails
{
public string Email { get; set; }
public string BusinessId { get; set; }
}
public static BusinessUserDetails JoinExistingSmeInitialize(string email = null)
{
var rand = new Random();
var randNumber = rand.Next(1, 9999999);
email = email ?? "auto-test_" + randNumber + "@mailinator.com";
return new BusinessUserDetails
{
Email = email,
};
Im converting it to Java and have got this far
public class BusinessUserDetails
{
private String Email;
public final String getEmail()
{
return Email;
}
public final String setEmail(String value)
{
Email = value;
return value;
}
private String BusinessId;
public final String getBusinessId()
{
return BusinessId;
}
public final void setBusinessId(String value)
{
BusinessId = value;
}
}
public BusinessUserDetails JoinExistingSmeInitialize(String email) {
Random rand = new Random();
int randNumber = rand.nextInt(9999999);
email = (email != null) ? email : "auto-test_" + randNumber + "@mailinator.com";
}
The one i cant seem to convert is this
return new BusinessUserDetails
{
Email = email,
};
any help would be appreciated!
Upvotes: 2
Views: 47
Reputation: 2270
Java doesn't have that kind of constructor initialization. You need to create a constructor that takes a String
as a param:-
public BusinessUserDetails(String email) {
Email = email;
}
and then the code you can't get to work would just be:-
return new BusinessUserDetails(email);
I would also recommend using Java coding conventions, especially not using a capital letter for instance names, as it will make understanding your code a lot easier.
Upvotes: 0
Reputation: 676
Use a constructor in your BusinessUserDetails
to set the Email
field. Then use :
return new BusinessUserDetails(email);
Upvotes: 1