The Source for Java Technology Collaboration
User: Password:
Register | Login help    

Search

Online Books:
java.net on MarkMail:


Fabrizio Giudici

Fabrizio Giudici is a Senior Java Architect with a long J2EE experience and in the latest two years he expanded his interests to Jini and NetBeans. Fabrizio has been running Tidalwave.it, his own consultancy company, since 2001 and has been a technical speaker at JavaOne, JavaPolis, Jazoon, Jini Community Meetings and some italian Java conferences. He started working with Java since the old 1.0 times and after 1.3 he has been committed in demonstrating that Java performance is not an issue, really. After bringing Java to the world of Formula One telemetry, he believes he is on the right path. Fabrizio is a member of the JUG Milano and the NetBeans Dream Team.

 

Fabrizio Giudici's blog

Three small updates about as(...)

Posted by fabriziogiudici on December 4, 2009 at 4:19 AM PST
I've previously blogged about the as(...) pattern I'm using for my projects. In an email exchange with Taylor Cowan, I've been made aware that Taylor has been using this pattern since a quite a few time in his JenaBean project (Jena is another big player in the world of RDF and Java). A stripped down pseudocode from his example:

object.as(DCTerms.class).title("thetitle").created("2006-09-07T09:33:30Z");

Have a look at his code since the examples are much more powerful than the excerpt above.

Second, another exchange with Tor Norbye (for a completely different topic) made me aware of an updated naming convention for Java identifiers containing acronyms. So, I'm now using SkosConcept and OwlThing in place of SKOSConcept and OWLThing.

Third, my friend Uberto Barbini suggested me that there's a way to get rid of that .class suffix, without hoping for a compiler change. If you define such a thing as:

public interface SkosConcept
  {
    public final static Class<SkosConcept> SkosConcept = SkosConcept.class;
   
    ...
  }

public interface GeoCoderEntityProxy
  {
    public final static Class<GeoCoderEntityProxy> GeoCoderEntityProxy = GeoCoderEntityProxy.class;
   
    ...
  }

you can write:

import static it.tidalwave.semantic.SkosConcept.SkosConcept;
import static it.tidalwave.geo.location.GeoCoderEntityProxy.GeoCoderEntityProxy;

List<GeoCoderEntityProxy> list = object.as(SkosConcept).findNarrowers().ofType(GeoCoderEntityProxy).results();

which is quite readable. The Java compiler is capable of understanding the difference between a type reference (for instance the GeoCoderEntityProxy generic parameter in List<>) and a field reference (such as the one statically imported). The only thing that you're loosing is that you won't be able to invoke an hypotethical static method such as GeoCoderEntityProxy.doSomething(). But in most cases I'm dealing with interfaces, so this is not a real issue.


Related Topics >> Blogs      
Comments
Comments are listed in date ascending order (oldest first)

Lombok

I could definitely see a Lombok annotation to help write the constant in the interface
Syndicate content