Generics can be declared on types (classes and interfaces), methods, and constructors. Wait, constructors? That one threw me a little. I’ve never actually seen or used this feature. It makes logical sense to be able to declare a generic type on a constructor; after all, it’s just a special case of a method.
I could explain how to declare and use generic constructors in a rigorous and academic way, but that doesn’t give us a sense of if or whether it’s actually a useful feature. Instead, let’s see how and how often they’re used in the real world. That’s why we have open source! Let’s look for examples of generic constructors in some of the most popular Java projects and see if we can find any patterns.
The Ceylon language takes a different approach to reading and writing files than Java. Consider the following methods in Java:
I got the Ergodox EZ in late 2015 and I love it. I’ve been tinkering with the layout ever since—that is, after all, the whole fun of buying one. Not many other keyboards on the market come close to providing this level of customization. Designing your own layout means you get to bend the keyboard to your will, not the other way around. I want to share some of what I’ve done and why I’ve done it.
On our way to building the “Internet of things”, we’ll end up creating the “Super Intelligence of things”. But what does that look like?
What if languages had a
.= operator? What would it do?
My wife has the Jawbone Up2 fitness tracker. It tracks things like steps, hours slept, etc. The mobile app has a Smart Coach feature which gives daily suggestions. Most of the time, the suggestions relate to information that only the tracker knows about, like “try to get more steps today”, or “try to go to bed 20 minutes earlier”. But yesterday, it made a suggestion about things I didn’t think it should have known about.
Many organizations use Subversion (or SVN) as their version control system (VCS) of choice. Often, SVN is so thoroughly baked into the organization’s processes—with build scripts, commit hooks, custom tooling, etc.—that it would be prohibitively expensive to change to a different VCS.
There’s nothing wrong with Subversion, but sometimes you want the power of Git. I personally prefer Git’s ability to commit locally and its branching model over SVN. Git can bidirectionally interact with Subversion repositories with the
git svn command.
I believe that, if done right, checked exceptions can benefit an API. However, they weren’t given the proper TLC in the new Java 8 APIs, particularly in the Streams. But if Java was enhanced with default generics, the mess could be cleaned up.
When we write libraries or frameworks, we sometimes have a class
Foo whose constructor takes a
Bars, where the
Bars will be supplied by dependents.
There are many articles that explain the broad applications of Java 8’s new
Optional class (e.g., Tired of Null Pointer Exceptions? Consider Using Java SE 8’s
Optional!), but they focus on how authors can use
Optional to improve the design of their own APIs. I want to talk about how
Optional can be used to protect us from the APIs we didn’t write.