Looking at the Java8 doc for OptionalInt
, it seems that OptionalInt
cannot be reused by setting a new value or emptying the existing value. Moreover the JavaDoc shows only two ways of initializing an OptionalInt by calling static methods - looks like an immutable object.
Is it really not reusable?
Imagine a batch processing, where the data to process consists of an int primitive, which is can be optional. For each row (let it be millions of rows) a new OptionalInt
object would have to be created. The goal is to avoid unnecessary object instantiation and the additional garbage collection. So I rather would have to reimplement it myself and avoid the Java8 utility class OptionalInt
?