我想将此代码块从Java转换为Kotlin:
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password");
}
})
但是我无法适当地转换此部分:
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username", "password")
}
如何进行对话?
这是一个匿名的类实例。检查object expressions
object : Authenticator() {
override fun getPasswordAuthentication() : PasswordAuthentication {
return PasswordAuthentication("username", "password")
}
}