<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4422336618483533247</id><updated>2011-07-07T15:45:16.102-07:00</updated><title type='text'>Coder Virtue</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codervirtue.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4422336618483533247/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://codervirtue.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jacek</name><uri>http://www.blogger.com/profile/12885082646599435086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_bbhhw7iLLuk/Sw-9ZXii-OI/AAAAAAAACSI/O8uy61JdTOE/S220/myface4.png'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4422336618483533247.post-4940374004386944377</id><published>2010-01-30T15:22:00.000-08:00</published><updated>2010-01-30T15:24:40.583-08:00</updated><title type='text'></title><content type='html'>Hi, I moved to &lt;a href="http://virtuecode.wordpress.com/"&gt;http://virtuecode.wordpress.com/&lt;/a&gt; primarily for its out of the box syntax highlighting support, not mentioning other superior features.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4422336618483533247-4940374004386944377?l=codervirtue.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codervirtue.blogspot.com/feeds/4940374004386944377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codervirtue.blogspot.com/2010/01/hi-i-moved-to-httpvirtuecode.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4422336618483533247/posts/default/4940374004386944377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4422336618483533247/posts/default/4940374004386944377'/><link rel='alternate' type='text/html' href='http://codervirtue.blogspot.com/2010/01/hi-i-moved-to-httpvirtuecode.html' title=''/><author><name>Jacek</name><uri>http://www.blogger.com/profile/12885082646599435086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_bbhhw7iLLuk/Sw-9ZXii-OI/AAAAAAAACSI/O8uy61JdTOE/S220/myface4.png'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4422336618483533247.post-2255138589973818939</id><published>2009-03-17T02:51:00.001-07:00</published><updated>2009-03-17T03:45:34.522-07:00</updated><title type='text'>Null-safe method invocation in Java 7</title><content type='html'>&lt;p&gt;There has been some &lt;a href="http://jroller.com/scolebourne/entry/java_7_null_ignore_invocation"&gt;discussion&lt;/a&gt; on null-safe method invocation in Java 7. Briefly there is a proposal to introduce a new ?. operator that would allow to call a method on a null object without throwing a NullPointerException (NPE). For instance:&lt;/p&gt;&lt;pre&gt;   List list = null;&lt;br /&gt;   System.out.println(list?.isEmpty()); // prints: false&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The most obtrusive part in the current state of proposals is assumption that the invocation on null object should always return null or a default value in case of primitives. In our example of list?.isEmpty() returning true would make much more sense then false, because semantically the null list does not have any elements so it is empty. The bottom line is that &lt;span style="text-decoration:underline;"&gt;what the method returns when called on a null object is an implementation detail of that method&lt;/span&gt;, so it should be specified in the method's body. The rest of this post proposes a way to do it.&lt;/p&gt;&lt;p&gt;If the method's body starts with if (this == null) statement, e.g.&lt;/p&gt;&lt;pre&gt;   class List {&lt;br /&gt;     public boolean isEmpty() {&lt;br /&gt;       if (this == null) return true;&lt;br /&gt;       return data.length == 0;&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;then Java 7 compiler could compile it to both the traditional method:&lt;/p&gt;&lt;pre&gt;   public boolean isEmpty() {&lt;br /&gt;     // the if (this == null) ... block is removed&lt;br /&gt;     return data.length == 0;&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;as well as to a static wrapper method:&lt;/p&gt;&lt;pre&gt;   private static boolean isEmptyNullSafe(List _this) {&lt;br /&gt;     if (_this == null) return true;&lt;br /&gt;     return _this.isEmpty();&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;(The name of the wrapper method must be generated by the compiler to prevent name clashes with methods already existing in the source code)&lt;/p&gt;&lt;p&gt;This way the isEmpty() method would work the same way if called normally:&lt;/p&gt;&lt;pre&gt;   list.isEmpty()&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;, throwing NPE.&lt;/p&gt;&lt;p&gt;But the null safe call:&lt;/p&gt;&lt;pre&gt;   list?.isEmpty()&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;would compile to:&lt;/p&gt;&lt;pre&gt;   List.isEmptyNullSafe(list);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;and return true, if the list is null.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4422336618483533247-2255138589973818939?l=codervirtue.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codervirtue.blogspot.com/feeds/2255138589973818939/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codervirtue.blogspot.com/2009/03/null-safe-invocation-in-java-7.html#comment-form' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4422336618483533247/posts/default/2255138589973818939'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4422336618483533247/posts/default/2255138589973818939'/><link rel='alternate' type='text/html' href='http://codervirtue.blogspot.com/2009/03/null-safe-invocation-in-java-7.html' title='Null-safe method invocation in Java 7'/><author><name>Jacek</name><uri>http://www.blogger.com/profile/12885082646599435086</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://1.bp.blogspot.com/_bbhhw7iLLuk/Sw-9ZXii-OI/AAAAAAAACSI/O8uy61JdTOE/S220/myface4.png'/></author><thr:total>12</thr:total></entry></feed>
