Why is JavaMail Transport.send() a static method?

Posted by skiphoppy on Stack Overflow See other posts from Stack Overflow or by skiphoppy
Published on 2010-02-16T16:36:36Z Indexed on 2010/05/24 12:41 UTC
Read the original article Hit count: 274

Filed under:
|
|

I'm revising code I did not write that uses JavaMail, and having a little trouble understanding why the JavaMail API is designed the way it is. I have the feeling that if I understood, I could be doing a better job.

We call:

transport = session.getTransport("smtp");
transport.connect(hostName, port, user, password);

So why is Eclipse warning me that this:

transport.send(message, message.getAllRecipients());

is a call to a static method?

Why am I getting a Transport object and providing settings that are specific to it if I can't use that object to send the message? How does the Transport class even know what server and other settings to use to send the message? It's working fine, which is hard to believe. What if I had instantiated Transport objects for two different servers; how would it know which one to use?

In the course of writing this question, I've discovered that I should really be calling:

transport.sendMessage(message, message.getAllRecipients());

So what is the purpose of the static Transport.send() method? Is this just poor design, or is there a reason it is this way?

© Stack Overflow or respective owner

Related posts about java

Related posts about javamail