Sunday Aug 24, 2008

Which of these is "better"?

Today I was studying this piece of code:

Lookup lkp = Lookups.forPath("MessageProviders");  

Collection  coll = (Collection) lkp.lookupAll(MessageInterface.class);  
for (Iterator it = coll.iterator(); it.hasNext();) {  
     MessageInterface messageInterface = (MessageInterface) it.next();  
     jTextArea1.append(messageInterface.getMessage());  
}

I figured out that I was able to rewrite it to this:

Lookup lkp = Lookups.forPath("MessageProviders");

Collection<MessageInterface> coll = (Collection<MessageInterface>) lkp.lookupAll(MessageInterface.class);
for (MessageInterface it : coll) {
    jTextArea1.append(it.getMessage());
}

Which of the two, in your opinion (this is inevitably going to be a subjective question of taste) is "better"? And why?

About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« August 2008 »
SunMonTueWedThuFriSat
     
2
4
5
6
7
11
14
17
20
23
27
29
30
31
      
Today