gpt4 book ai didi

c# - getter setter 文本字段 JAVA GUI

转载 作者:行者123 更新时间:2023-11-30 06:26:06 25 4
gpt4 key购买 nike

嗨,什么是 JAVA 等同于用 C# 编写的这种和平代码第 1 类:

  public string Password
{
get { return password; }
set { password = value; }
}

第 2 类:

        try
{

UserEntity user = new UserEntity();

user.Password = textBoxPassword.Text;
user.InsertUser();
MessageBox.Show("User is registred");

}

在java中我写了这个:第 1 类:

 protected int password ;


public int getPassword(){
return password;

}

public void setPassword(int password){
this.password=password;
}

类2:

 LoginEntity login = new LoginEntity();
login.getPassword() = pwdTextBox.getText();// here ERROR : required variable , found value

最佳答案

在 C# 和 Java 中,您都不能在赋值的左侧进行方法调用。所以这个:

login.getPassword() = pwdTextBox.getText();

在 Java 或 C# 中均无效

也许你想要

login.setPassword(pwdTextBox.getText());

尽管您真的应该避免使用字符串作为密码,因为它们很容易被嗅探,从而使您的密码保护不力。

关于c# - getter setter 文本字段 JAVA GUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14821588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com