Why no public constructor for Optional in java?

  • A+
Category:Languages

Why Optional has methods like of() and ofNullable() instead of a public constructor?

 


Optional is a Value-based Class without any constructors

do not have accessible constructors, but are instead instantiated through factory methods which make no committment as to the identity of returned instances

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: