Why is access restricted to jre6/lib/rt.jar for OperatingSystemMxBean?

后端 未结 4 931
陌清茗
陌清茗 2020-12-18 21:30

I\'m having a little trouble with some Java code I\'m trying to compile in Eclipse. I keep getting the following warning...

Access restriction: The type Ope         


        
4条回答
  •  萌比男神i
    2020-12-18 22:12

    This is not a problem of license agreements. It is just Eclipse trying to protect you from using classes that are not part of the official JDK API (but rather, part of Oracle/Sun's JVM implementation).

    Is there a particular reason that you need to class cast (rather than using the "official" interface java.lang.management.OperatingSystemMXBean)?

    If you want to make sure that your application continues to run when the expected MXBean is not available, you could add some try/catch logic to gracefully handle a ClassCastException.

提交回复
热议问题