Adam Bien's Weblog

Sunday Jul 01, 2007

(T) vs. t.cast in p4j5, or the opensource effect

Immediately after opensourcing the first utilities in the Java EE 5 Patterns project, I got not only many requests for developer role, but also some good feedback. In the ElementLocator utility, I wrote the following code:

   public <T> T getElement(String jndiName,Class<T> t){
        Object component = this.getElement(jndiName);
        return (T)PortableRemoteObject.narrow(component, t);
    }

the problem is the cast, which causes warnings, which is in turn sub-optimal :-).

Robert Herschke sent me the following snippet, which was immediately committed to the trunk:

public <T> T getElement(String jndiName,Class<T> t){
       Object component = this.getElement(jndiName);
       return t.cast(PortableRemoteObject.narrow(component, t));
   }

I invited him to get the developer role, but he had to work :-).


[This entry is based on / extends my books: Enterprise Architekturen, Leitfaden fuer effiziente Software-Entwicklung and: Java EE 5 Architekturen, Patterns und Idiome]

 Subscribe in a reader

Kommentare:

Senden Sie einen Kommentar:
  • HTML Syntax: Ausgeschaltet
About,RSS / Atom

About me: www.adam-bien.com
JavaONE 2008 Interview
My Recent Books
Adverts
Search
Links
greenfire.dev.java.net
...the last 150 posts
my.netbeans.org
Visitors
License