gpt4 book ai didi

java - 屏蔽从控制台输入的密码, "Cannot resolve symbol ' console'"

转载 作者:行者123 更新时间:2023-12-01 06:28:05 26 4
gpt4 key购买 nike

所以当我尝试编译这段代码时,我得到:

java: 找不到符号符号:类控制台位置:类java.lang.System

我不明白为什么当我启动控制台对象时,System.console()无法解析...

import java.io.Console;
import java.util.Arrays;
import java.util.Scanner;


public class User {
Scanner input = new Scanner(System.in);
Console console = new System.console();

private String userID, userPW, userPIN;
private char[] password = new char[6];


public String getUserID() {
return userID;
}

public void setUserID(String userID) {
this.userID = userID;
}

public String getUserPW() {
return userPW;
}

public void setUserPW(String userPW) {
this.userPW = userPW;
}

public String getUserPIN() {
return userPIN;
}

public void setUserPIN(String userPIN) {
this.userPIN = userPIN;
}

public void setUserInfo() {
System.out.print("Please enter your User ID : ");
this.setUserID(input.nextLine());

System.out.print("Please enter your Password: ");
this.setUserPW(input.nextLine());

this.password = console.readPassword("Enter password");
Arrays.fill(this.password, '*');
}

最佳答案

不是

Console console = new System.console();

应该是

Console console = System.console();

关于java - 屏蔽从控制台输入的密码, "Cannot resolve symbol ' console'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16505025/

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