why a Socket is not instanceof Closeable at runtime?

后端 未结 3 1083
名媛妹妹
名媛妹妹 2020-12-21 09:35

In an Android app, I added this code to onCreate()

    Closeable sss = new Socket();
    if (!(sss instanceof Closeable)) {
        throw new Runtim         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-21 09:53

    For future readers, I want to clarify something that was assumed to be evident by everyone in this discussion:

    How could I assign Closeable sss = new Socket(); if Socket is not Closeable?

    The API requirements specified in AndroidManifest.xml are:

    
    

    and the device reports

    android.os.Build.VERSION.SDK_INT=16
    

    The code was compiled for API level 19, this is why it was successfully compiled. But it was run on API level 16, and this is why it failed.

    In other words, the compile-time check was performed for API19 on one computer (the desktop PC) while the run-time check was performed for API16 on another computer (the handheld device).

提交回复
热议问题