Implementing the Builder pattern in Java is tedious, error-prone and repetitive. Who hasn't seen a ten-argument constructor, thought cross thoughts about the previous maintainers of the class, then added "just one more"? Even a simple four-field class requires 39 lines of code for the most basic builder API, or 72 lines if you don't use a utility like AutoValue to generate the value boilerplate. F
@Value.Builder record Player(int id, String name, boolean active) implements WithPlayer {} Player player = new PlayerBuilder() .id(11) .name("Constantine") .active(true) .build(); Player copy = player .withId(1) .withName("Variant") .withActive(false); @Value.Immutable interface Book { String isbn(); String title(); List<String> authors(); } ImmutableBook book = ImmutableBook.builder() .isbn("978-
TL;DR JDK(tools.jar)中、com.sunパッケージ配下に、javacが内部的に使っている「com.sun.tools.javac.util.List 」が含まれており、これは不変データ構造としてのリストのように(Cons セルベースのリストのように)利用できる。 はじめに ScalaのコードをGroovyやJavaなどに移植する際に、いつも悲しい思いをするのが不変データ構造に基づいたリスト処理ライブラリが見あたらない、ということでした。JDKの標準コレクションライブラリには、Scalaのscala.collection.immutable.Listのような、不変データ構造を用いて実装されているリストがありません。 ここで言う不変データ構造に基づいたリストとは、JDKのjava.util.Collections.unmodifiableList()等で取得できるような変更禁
Java is one of the most popular programming languages around, but no one seems to enjoy using it. Well, Java is actually an alright programming language, and since Java 8 came out recently, I decided to compile a list of libraries, practices, and tools to make using Java better. "Better" is subjective, so I would recommend taking the parts that speak to you and use them, rather than trying to use
@Value.Builder record Player(int id, String name, boolean active) implements WithPlayer {} Player player = new PlayerBuilder() .id(11) .name("Constantine") .active(true) .build(); Player copy = player .withId(1) .withName("Variant") .withActive(false); @Value.Immutable interface Book { String isbn(); String title(); List<String> authors(); } ImmutableBook book = ImmutableBook.builder() .isbn("978-
we write about the things we build and the things we consume I finally got to play with Java 8 streams and lambdas in more than a “Hello, World” way a couple of weeks ago. It was all pretty basic stuff—a map here, a few filters there, a sprinkling of counts—but it’s lovely to finally have first-class support for things we’ve been using in Guava for years, and lambdas make the syntax much more ters
public final class ImmutablePair<L, R> { public static <L, R> ImmutablePair<L, R> of(L left, R right){ return new ImmutablePair<>(left, right); } private ImmutablePair(L left, R right) { this.left = left; this.right = right; } private final L left; private final R right; public L left() { return left; } public R right() { return left; } public ImmutablePair<L, R> right(R r) { right = r; return thi
このエントリはJava Advent Calender 2011の第14日目です。 OOPで最も重要なテクニックは何でしょうか。色々な考え方があるでしょうが、ボクはImmutable Objectがまず最初に浮かびます。 かなり前にJava World誌に書いていたJavaデザインノートという連載でも、第1回のテーマはImmutable Objectでした。 Immutable Object(不変オブジェクト)は、生成時に属性を設定した後、属性値を変更することができないオブジェクトです。Javaの場合、StringやDateなどの情報を保持する基本クラスの多くがImmutable Objectになっており、Javaプログラミングを下支えしています。 Immutable Objectの長所は、とにかく属性値が変更されないこと。一度生成したオブジェクトは何の心配もなく、メソッドの引数で渡すこと
Java is one of the most popular programming languages around, but no one seems to enjoy using it. Well, Java is actually an alright programming language, and since Java 8 came out recently, I decided to compile a list of libraries, practices, and tools to make using Java better. This article is on Github. Feel free to contribute and add your own Java tips and best practices. Style Structs The Buil
The document discusses the performance considerations of the Java Virtual Machine (JVM) and its impact on low-latency applications, focusing on concepts like garbage collection (GC), memory management, and adaptive compilation. It highlights strategies for optimizing JVM performance, including the use of short-lived immutable objects, managing object allocations, and understanding the differences
Trail: Essential Java Classes Lesson: Concurrency Section: Immutable Objects The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Dev.java for updated tutorials taking advantage of the latest releases. See Java Language Changes for a summary o
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く