Java small knowledge point

xiaoxiao2021-03-06  42

1, instanceof and getclass (). GetName (). COMPARETO () Differences and Contact

<1> InstanceOf is the keyword is in the JVM; it is used to determine if an instance belongs to a certain class or his parent class;

<2> getClass (). Getnname () returned to the true class name, so when it is compared to the parent class of the class;

EG.

String TT = New String ("");

IF (tt.getclass (). getname (). Compareto ("java.lang.string") == 0) // RTURN TRUE;

IF (tt.getclass (). getname (). Compareto ("java.lang.object") == 0) // Return False;

IF (TT InstanceOf String) // Return True;

IF (TT InstanceOf Object) // Return False;

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

New Post(0)