0

I have a class, shown below, which needs to be able to use equals in the way int does, for example: you don't say

int i = new Integer(1);

you say

int i = 1;

how do i define what happens when = is invoked on a class?

And what is the difference between

    int i1 = new Integer(5);

and

    Integer i2 = new Integer(5);
Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
AlphaModder
  • 3,266
  • 2
  • 28
  • 44
  • 1
    NO operator overloading in java. check http://stackoverflow.com/questions/1686699/operator-overloading-in-java – Subin Sebastian Nov 17 '12 at 06:06
  • `=` is *never* "invoked on a class/value". Ever. It assigns a value (sometimes a "reference to an object") to a variable (or member variable). That's it. Look, no class involved: `int i = 1;` or `String s = null;` In this case, look up "auto boxing". –  Nov 17 '12 at 06:08

1 Answers1

4

You can't, it is only defined in the language and you can't change it. Btw, what you're mentioning is called "autoboxing" and only happens for primitive times since Java 1.5

Parth Soni
  • 11,158
  • 4
  • 32
  • 54
OscarRyz
  • 196,001
  • 113
  • 385
  • 569