Spring Boot 整合 Quartz 集群執行預設及動態排程
介紹如何在 Spring Boot 整合 Quartz 集群框架中同時實作預設及動態排程
2022-11-15    
Quartz 介紹
簡介 Quartz 這個 Java 生態圈有名的排程框架
2022-11-15    
Spring Boot 後端實作 XSS 防範
介紹 Spring Boot 整合 Spring Security 後端專案如何提供 XSS 基本防範
2022-11-01    
XSS 防範簡介
介紹 XSS 攻擊及簡單防範概念
2022-11-01    
Java Optional 為何不推薦做為類別屬性

大家有在寫 Java 1.8+ 的時候使用新出的 Optional 類別來處理 null 的問題嗎?

那在使用的時候有沒有碰到 IntelliJ 提示 Optional 不推薦用來當作類別的 field 的黃色警告 (warning) 呢?訊息應該大致如下

/**
 * A container object which may or may not contain a non-{@code null} value.
 * If a value is present, {@code isPresent()} returns {@code true}. If no
 * value is present, the object is considered <i>empty</i> and
 * {@code isPresent()} returns {@code false}.
 *
 * <p>Additional methods that depend on the presence or absence of a contained
 * value are provided, such as {@link #orElse(Object) orElse()}
 * (returns a default value if no value is present) and
 * {@link #ifPresent(Consumer) ifPresent()} (performs an
 * action if a value is present).
 *
 * <p>This is a <a href="../lang/doc-files/ValueBased.html">value-based</a>
 * class; use of identity-sensitive operations (including reference equality
 * ({@code ==}), identity hash code, or synchronization) on instances of
 * {@code Optional} may have unpredictable results and should be avoided.
 *
 * @apiNote
 * {@code Optional} is primarily intended for use as a method return type where
 * there is a clear need to represent "no result," and where using {@code null}
 * is likely to cause errors. A variable whose type is {@code Optional} should
 * never itself be {@code null}; it should always point to an {@code Optional}
 * instance.
 *
 * @param <T> the type of value
 * @since 1.8
 */

我剛碰到的時候感覺很奇怪,用 Optional 來當 field 表示我們想表達這個 field 有可能是 null 有什麼不對嗎?為什麼 IntelliJ 要警告我呢?

2022-10-01    
ProtoBuf FlatBuf Benchmark in Java
Benchmarking ProtoBuf and FlatBuf with Java
2022-01-04    
gRPC 概念
釐清 gRPC 概念
2021-12-27    
HTTP/2 系列 - HTTP Server Push 技術
探討建構在 HTTP 協定上的 Server Push 技術
2021-12-24    
HTTP/2 系列 - HTTP/2 概念
釐清 HTTP/2 概念
2021-12-21    
在 Batch Script 壓縮檔案
紀錄如何在 Batch Script 中壓縮檔案
2021-12-16