Hi Ivan,

An enum for the OS is useful but as proposed is spread over too many files and into the build system too. The construct is not really a compile time constant since it is initialized as part of a static initializer. The initialization could just as easily be done in OS.java by checking the system property.
The sun.misc.OS class can be self contained.

There should probably also be an isWindows() method.

As for switch, there are hidden costs associated with using switch on enum, including an extra generated class for every class that uses the enum and static initialization.

Roger


On 1/4/2015 6:03 AM, Peter Levart wrote:

On 01/03/2015 06:39 PM, Ivan Gerasimov wrote:

...
Hi Ivan,

There were other cases where one wanted to consolidate duplicated code, but couldn't easily because of subtle differences among OS platforms (UNIXProcess is one of such cases). Perhaps we need something like this:

http://cr.openjdk.java.net/~plevart/misc/OS/webrev/

With this compile-time mechanism, one can use switch or if statements in common class to cover subtle differences and only divide code into OS platform specific classes where the bulk of it differs.

What do you think?

Regards, Peter


Sincerely yours,
Ivan



Reply via email to