这些java语句的格式代表什么意思

Session session = Session.getDefaultInstance(props, new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } });这只是一个句子,这个格式怎么这么奇怪?还有其中又有一个类这又是什么情况???
2026年09月23日 06:01
有2个网友回答
网友(1):

我认为  Authenticator应该是一个借口,  new Authenticator当然会生成一个类了,

new Authenticator()  {   
    public PasswordAuthentication 
    getPasswordAuthentication()   
    {    
        return new PasswordAuthentication(username, password);   
    }

这个是一个类,但是没有类名,这个叫做匿名内部类吧,   

网友(2):

建议你去下载一份java API文档,要自己学会查文档,里面应有尽有