0

I'd like to convert this block of code from Java to Kotlin:

 Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("username", "password");
            }
          })

But I'm unable to appropiately convert this part:

 protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("username", "password")
            }

How could that conversion be made?

lugiorgi
  • 473
  • 1
  • 4
  • 12
user2638180
  • 1,013
  • 16
  • 37
  • 3
    Does this answer your question? [How to create an instance of anonymous class of abstract class in Kotlin?](https://stackoverflow.com/questions/17516930/how-to-create-an-instance-of-anonymous-class-of-abstract-class-in-kotlin) – DCTID Feb 05 '20 at 22:06

1 Answers1

1

That is an anonymous class instance. Check object expressions

object : Authenticator() {
    override fun getPasswordAuthentication() : PasswordAuthentication {
        return PasswordAuthentication("username", "password")
    }
}
Juan Rada
  • 3,513
  • 1
  • 26
  • 26