You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Say I've got a controller class, that effectively delegates to a service, retrieves some domain objects, and converts them to another data type that better serializes to JSON and contains some additional metadata.
Say I have a class with a potentially-null field and I want to sort a List of class instances on that field first (nulls last), then fall back on a second non-null field.
To be clear, this post is not about using Groovy to make collect calls (Are collect phone calls still a thing? Do people nowadays even know what they are?). No, I am talking about calling methods named collect, which may seem banal but actually warrants attention, especially in light of Groovy 3's long-awaited and much-anticipated release.
Groovy has long provided Closures and extension methods on Iterable and Iterator to implement Java 8 Stream-like capabilities, even when running on Java 7 or earlier.
Using these capabilities to, say, square all even numbers between 1 and 10, would look akin to this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Constructor Injection that feels like Field Injection. Lombok generates a constructor for all final fields.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Single Item List Showdown: Collections::singletonList vs. List::of
How do you take a single Java object of type T and turn it into a single-element List<T>?
One way, of course, is to instantiate some List implementation like ArrayList or LinkedList and add the item, but where's the fun in that? Saavy developers like us want to do such banal things in a single line of code. The good news is that JavaSE provides multiple single-line-of-code approaches to address this problem.
(I'm going to ignore the so-called "double brace" instantiation approach because even though you can create the single-item list and assign a reference in one statement, it uses two lines of code: one line to instantiate the anonymous List subtype and one line inside the initializer block to add the item.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
As a resident Java Subject Matter Expert within my organization, I've been paying close attention to the happenings surrounding Java over the past two years: the modular JDK, the six month release cadence, the growing significance of OpenJDK, and Oracle JDK 11's new license.
I hope to help my organization, which is highly invested in Java, appropriately navigate these changes by not falling woefully behind in the versions of Java used, by ensuring our JVMs are secure and can be patched, and by not unintentionally violating any software licenses. Achieving this aim starts with educating other stakeholders, especially upper management. I've found it helpful to explain these recent happenings to a less technical audience by framing Java's changes in a historical context--namely, in terms of "eras."
The Era of Stability
The Java 5.0 release in September of 2004 ushered in an important era in Java's history. It brought significant changes to the language and its Standard Ed
Looks like field injection, behaves like constructor injection.
Spring (and likely other IoC frameworks) offer three dependency injection approaches:
Constructor-based - Spring injects dependencies as constructor arguments when instantiating a bean
Developers using Lombok with Spring can create annotation-configured beans easily with the Lombok @RequiredArgsConstructor annotation.
Setter-based - Spring creates a bean through its default calls setter methods to