gpt4 book ai didi

java - 将 getPasswordAuthentication 函数转换为 Kotlin

转载 作者:行者123 更新时间:2023-12-02 09:02:08 26 4
gpt4 key购买 nike

我想将此代码块从 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")
}
}

关于java - 将 getPasswordAuthentication 函数转换为 Kotlin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60084737/

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