TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JDK 8 calendar builder

12 pointsby chookrlalmost 12 years ago

3 comments

mythzalmost 12 years ago
A good example of bloatware encouraged by a non-expressive language. Instead of adding a language feature that makes constructing any instance easier, in 2013 they're adding support for a builder on a single Calendar class.<p><pre><code> final Calendar calendar = new Calendar.Builder() .set(YEAR, 2013) .set(MONTH, APRIL) .set(DATE, 6) .build(); </code></pre> For a similar API in C# you could use named parameters:<p><pre><code> var calendar = new Calendar(year:2013, month:Month.April, date:6); </code></pre> or just set public properties in an object initializer:<p><pre><code> var calendar = new Calendar { Year = 2013, Month = Month.April, Date = 6, }; </code></pre> Likewise in Dart with named parameters:<p><pre><code> var calendar = new Calendar(year:2013, month:APRIL, date:6); </code></pre> or using method cascades:<p><pre><code> var calendar = new Calendar() ..year = 2013 ..month = APRIL ..date = 6; </code></pre> For C#, Dart you get this for free when constructing any object. Java requires creating the boilerplate of a builder for every class?? and with all that effort it's still more verbose.
评论 #5771797 未加载
RyanZAGalmost 12 years ago
To be honest, this just seems like bloating the JRE even further with stuff that can be in a library (and is - JODA time?). I can't wait for Java 9 (I think?) that will finally work on modularising the JRE so I don't have to include most of this stuff if not needed...
crypto5almost 12 years ago
I was always curious, why they called this class as Calendar. It's actually date/datetime/time.
评论 #5772914 未加载