Java – in the getClass () document, what does “erase the static type of the called expression” mean?

The document of "public final class getclass()" method of object says:

I don't understand the explanation, especially about what | x | is considered - "delete the static type of the expression called by getClass"

|What form does x |? Or maybe | x | uses type symbols elsewhere?

Solution

The method of Java language specification demands is handled by the compiler in a special way:

Therefore, the return type of getClass is the static (compile time) type of the expression calling getClass () For example:

String s = "";
Object o = s;
Class<? extends String> sc = s.getClass(); // ok
Class<? extends Object> oc = o.getClass(); // ok
oc = sc; // ok
sc = o.getClass(); // not ok
sc = oc; // not ok

The symbol | x | is defined. The specifications are as follows:

For example, if we have:

List<String> list = ...;

Expression list The type of getclass() is instead of class < string > >

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
分享
二维码
< <上一篇
下一篇>>