System.getEnv(String name, String def)
Roger Riggs
roger.riggs at oracle.com
Mon Feb 15 14:13:05 UTC 2021
Hi,
An alternative to a new API is to use the general purpose
java.util.Objects.requireNonNull(T,T);
Objects.requireNonNullElse(System.getEnv(String key), "n/a"));
But a defaulting overload is straightforward.
Regard, Roger
On 2/15/21 8:59 AM, Loïc MATHIEU wrote:
> Hello,
>
> I wonder if there has already been some discussion to provide
> a System.getEnv(String name, String def) method that allows to return a
> default value in case the env variable didn't exist.
>
> When using system properties instead of env variable, we do have a
> System.getProperty(String key, String def) variant.
>
> Stating the JavaDoc of System.getEnv():
> *System properties and environment variables are both conceptually mappings
> between names and values*
>
> So if system properties and environment variables are similar concepts,
> they should provide the same functionalities right ?
>
> This would be very convenient as more and more people rely on
> environment variables these days to configure their applications.
>
> Regards,
>
> Loïc
More information about the core-libs-dev
mailing list