我正在创建一个扩展 java.net.Authenticator 的类来验证我的 FTP 代理。我使用密码验证时遇到错误...
import java.net.Authenticator;
import java.net.PasswordAuthentication;
class ProxyAuthenticator extends Authenticator {
private String user, password;
public ProxyAuthenticator(String user, String password) {
this.user = user;
this.password = password;
}
//error here
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password.toCharArray());
}
}
我知道人们之前已经使用过这些确切的代码行,没有任何错误。知道出了什么问题吗?
编辑:导入 java.net.PasswordAuthentication 后,我收到一条错误消息
java.net.Authenticator.getPasswordAuthentication
“覆盖 java.net.Authenticator.getPasswordAuthentication”
最佳答案
您缺少 PasswordAuthentication
的导入类!!
您可以使用完全引用的路径,例如 a.b.c.s.y.PasswordAuthentication
而不仅仅是PasswordAuthenticator
或者您使用导入来包含该类,就像您对 Authenticator
所做的那样类。
关于java - 密码验证无法解析为类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15530207/