如何在方法调用中描述方法? getInstance的原型(prototype)是getInstance(Properties, Authenticator)。这里编写了一个方法来代替 Authenticator。请建议我可以找到解决此类问题的地方。
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
最佳答案
这是一个匿名内部类。抽象类 javax.mail.Authenticator 有一个名为 getPasswordAuthentication 的方法。此代码使用声明的方法覆盖该方法。
关于java - 方法内部调用java方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38133002/