can't call String.isEmpty() in android

前端 未结 7 558
一向
一向 2021-02-01 12:05

In my android application I can\'t use String.isEmpty() function which is situated in JDK 1.6. Android 2.1 lib doesn\'t have this function in java.lang

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-01 12:30

    How can I solve this problem and allow my application to use this function?

    You can't.

    Use String.length() == 0 instead. It is backwards compatible all the way back to JDK 1.0 ... and with J2ME as well.

    String.equals("") is another alternative.


    Are you sure that there is no way to configure Eclipse to put into a code classes from definite libraries?

    Not if you want your app to run on a real Android device. Java / Android platforms intentionally make it hard for you to tinker with the behaviour of the core class libraries. For a start, you can only do it by modifying the Davlik equivalent of the bootclasspath or rt.jar file, and neither of these can be done within a running JVM.

    That kind of tinkering has the risk of potentially breaking Java for other apps. Even assuming that you can't compromise Android app separation directly (because of the process/uid separation mentioned below), malicious tweaks to the (shared) Java core classes could still potentially allow one app to interfere with, or steal information from another app.

提交回复
热议问题