What’s the difference between Java’s equals () and C’s operator = =?

When a question regulating the use of typeID is C, I suggest it can be used to compare types in objects I don't see it doing well, but I have Java equality

Looking into Java a bit more, this seems to be like this: some say should compare the actual classes of two objects, and some say instanceof is the correct tool, which may be double scheduling Of course, one of the two situations is the most appropriate, but at least both options are considered

In C, Otoh, I can hardly find the code to compare with the actual type In most cases, using dual scheduling (using dynamic_cast), I can't find anyone who insists that fast type comparison is the right thing to do while waiting for the check to start

I wonder why there are two acceptable solutions to the problem of polymorphic type comparison in Java and only one seems to be considered a best practice in C? Are there significant technical differences, or just different approaches?

Note: my statement is based on impression, not specific knowledge If they are wrong, Java and C are indeed similar in this regard - or different from the above reasons, which is obviously an acceptable answer

Solution

In Java, all types ultimately derive from object and object

The reason why you don't see the problem discussed in C is, of course, because you don't define = =, unless there is some logical meaning, and then you define its logical meaning according to it. In Java, you usually have to define equals. Anyway, you must "invent" some meaning. You get to discuss what the meaning of invention should be

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