Home > Back-end >  The string class in Javase equals comparison function
The string class in Javase equals comparison function

Time:09-16

CD. Equals (which cd1);



Public Boolean equals (Object obj) {
CD cc=obj (CD);
Return artist. Equals (cc. Artist)}

In this case, the part of the code CD is my own to create a class, CD and which cd1 is refers to the object of this class, and then create a equals function to compare the two objects are equal,
I want to ask is there incoming equals function is which cd1, then equals function return two artist, the second refers to in which cd1, but the former refers to the artist in the CD? Not only introduced into which cd1 that an object? CD artist can also directly call here?

CodePudding user response:

You define the class member function equals is?

CodePudding user response:

The
refer to the original poster Cokey1 response:
CD. Equals (which cd1);



Public Boolean equals (Object obj) {
CD cc=obj (CD);
Return artist. Equals (cc. Artist)}

In this case, the part of the code CD is my own to create a class, CD and which cd1 is refers to the object of this class, and then create a equals function to compare the two objects are equal,
I want to ask is there incoming equals function is which cd1, then equals function return two artist, the second refers to in which cd1, but the former refers to the artist in the CD? Not only introduced into which cd1 that an object? CD artist can also directly call here?

Artist should be a member variable defined you, you can take a look at this is how come of, is not in this method, in this class, don't declare variables that can't use

CodePudding user response:

Is the first artist ". This artist "shorthand, omitted this

CodePudding user response:

1.==and equals () is used to compare data is the same way,
2. The difference:
Comparative content:
==: any data type can be compared, can compare basic data types, also can compare the reference data type
The equals () :
can only compare the reference data typeComparing different rules:
==: at the time of more basic data types, compare the data itself, the comparison is the reference data types, compare the address values
Equals () : before rewriting, compare the address values, after rewriting, according to rewrite the rules of the comparison

CodePudding user response:

The
refer to the original poster Cokey1 response:
CD. Equals (which cd1);



Public Boolean equals (Object obj) {
CD cc=obj (CD);
Return artist. Equals (cc. Artist)}

In this case, the part of the code CD is my own to create a class, CD and which cd1 is refers to the object of this class, and then create a equals function to compare the two objects are equal,
I want to ask is there incoming equals function is which cd1, then equals function return two artist, the second refers to in which cd1, but the former refers to the artist in the CD? Not only introduced into which cd1 that an object? CD artist can also directly call here?



Because you can already instantiated CD class, your call is also a CD class the equals method, method of the variable in a default is similar, so CD. The artist can call, of course,
  • Related