我正在将我的C#selenium框架中的方法转换为Java等价物 除了下面显示的特定方法外,一切都很好
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,
};
我将它转换为Java并且已经有了这个目标
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";
}
我似乎无法转换的是
return new BusinessUserDetails
{
Email = email,
};
任何帮助将不胜感激!
答案 0 :(得分:1)
使用BusinessUserDetails
中的构造函数设置Email
字段。然后使用:
return new BusinessUserDetails(email);
答案 1 :(得分:0)
Java没有那种构造函数初始化。您需要创建一个以String
作为参数的构造函数: -
public BusinessUserDetails(String email) {
Email = email;
}
然后您无法上班的代码就是: -
return new BusinessUserDetails(email);
我还建议使用Java编码约定,特别是不要使用大写字母作为实例名称,因为这样可以更容易地理解代码。