python - How to overload equality and print in java? -


In Java, how can you increase the surcharge operation and print operation for a class?

Python, you can do def __eq __ (self): or def __str __ (self): , but how to do it in Java can be done?

I know that you can make a method manually and call it like equal or something else, but I want to know whether any real person Which works with ==

thanks

< P> Java does not support operating overloading. The == reference will always test for equality.

Used to generate its output you can override toString in your class.

And you are right about overriding the method with a warning: If you are overriding the equal method, then you should also override the method so that Treat your object with the correct HashSet and so on. Details about the contract between Hashod and equals

/ edit

  public class point {private} Int x; Private int y; Public point (int x, int y) {this.x = x; this. Y = y; } @ Override public string toasting () {return "(" + + "," + y + ")"; } Public static zero main (string [] args) {System.out.println (new point (1, 2)); }}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -