Why sun.management.OperatingSystemImpl is package visible?

2.3k Views Asked by At

This class has really helpful methods. I can call them by reflection. But why I forced to do it?

I would like to cast OperatingSystemMXBean to OperatingSystemImpl and call them normal way.

Thanks in advance.

1

There are 1 best solutions below

1
Hassen Bennour On BEST ANSWER

can you explain why you would like to cast OperatingSystemMXBean to OperatingSystemImpl since OperatingSystemImpl implements OperatingSystemMXBean.

you can use it

    java.lang.management.OperatingSystemMXBean os = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    System.out.println(os.getArch());

or

    com.sun.management.OperatingSystemMXBean osBean = ManagementFactory
            .getPlatformMXBean(com.sun.management.OperatingSystemMXBean.class);
    System.out.println(osBean.getProcessCpuLoad() * 100);
    System.out.println(osBean.getSystemCpuLoad() * 100);