Analysis of keyword instanceof in Java

xiaoxiao2021-03-06  40

, I am dizzy, I am very dizzy ~~.

When you look at the JDK Wish code, you see some non-common keywords, at least I have used, or you will not use it, find some information, organize.

InstanceOf: It is useful to know the object type at runtime. We can't ignore the type of object when programming. One method is forced to convert. Another method is to use instanceof. But illegal forced conversion We also saw a lot and yourself, huh, huh, you don't do it when you test.

It's blamed.

What is instanceof? For example, the earth people understand.

Public void test (Object value) {

Value InstanceOf Integer {

// If Value is Integer, enter here

} else {

// .....

}

}

If a forced conversion is used

Public void test (Object value) {

Integer Integer = (Integer) Value; // If you call text (object) {} in other places, it is possible to throw it here.

Integer.// No at 3721, INTEGER is started.

}

Write this now.

转载请注明原文地址:https://www.9cbs.com/read-75165.html

New Post(0)