Search |
|||
Fabrizio Giudici's blogThree 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)
|
CategoriesArchivesDecember 2009
November 2009 October 2009 September 2009 August 2009 July 2009 June 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 July 2008 June 2008 May 2008 April 2008 March 2008 February 2008 January 2008 December 2007 November 2007 October 2007 September 2007 August 2007 July 2007 June 2007 May 2007 April 2007 March 2007 February 2007 January 2007 December 2006 November 2006 Recent Entries |
||
|
|
Lombok