Java and type security

When comparing Java and JavaScript, the MDN JavaScript guide explains the following:

Of course, with regard to the first part of the above statement, when it comes to the general concept of type safety, the ability to provide some kind of check around the language eliminates the possible error conditions of operations performed with incompatible types (even if the above example naively considers that in Java, you can encapsulate the original int into the reference type integer)

But what exactly does the second part of the statement mean?

Here discusses the verifier of JVM to ensure a certain degree of memory protection - "arbitration bit mode cannot be used as address"

How does the second part of the MDN declaration relate to type safety?

Solution

This means that in Java, there is no way to bypass how to recognize types In JavaScript, the type can be inferred from the sequence of bytes representing a piece of data In Java, VM can prevent this situation to ensure that the byte sequence as a foo object cannot be regarded as a bar object

With regard to accessing private members, this means that you can't make a series of bytes mean something different from the programmer's intention to obtain access to unexpected content At runtime, you cannot change an object foo of foo type with a private member foobar to an object of type bar with the same member but foobar is exposed The type of each object is encoded in bytecode, which is controlled by the VM at runtime

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>