English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

does java support operation overloading concept?please help with an example

2007-02-07 15:17:48 · 3 answers · asked by arul 1 in Computers & Internet Programming & Design

3 answers

Yes, it's possible. If you need it, you should have to explain WHY you want to to a friend, and make sure that they agree that you need it prior to doing it, since it's generally a bad idea in Javar.

2007-02-07 16:04:27 · answer #1 · answered by Anonymous · 1 0

yes possible,

> The philosophy behind that may be that
> overloading is not necessarily
> intrinsically "bad", but has the potential
> to generate unintuitive code.

On the other hand, if you've ever tried to make a nice matrix Class, you realize why operator overloading is so useful. Having the option available means you are able to apply a more natural coding style when it applies. Further, I have seen far too many unintuitive method and variable names to accept this argument.

> The one supported instance of String
> concatenation is a natural and intuitive
> use of overloading.

To continue my point, having to write something like

u = v1.add(v2);

to add two vectors (as used in Physics, i.e. magnitude and direction) is much more awkward than

u = v1 + v2;

in this context, since this style of infix mathematical notation is the most natural for the problem domain of Physics.

> Also, to eliminate it just in principle for
> consistency would deprive Java programmers of
> an extremely useful timesaver.

I agree that I wouldn't be as happy programming Java without the String concatenation operator. However, my argument for consistency would be in support of a general operator overloading mechanism rather than elimination of String concatenation.

2007-02-07 15:34:07 · answer #2 · answered by parashu N 1 · 1 1

yes operator overloading in java is possible but thats not suggested unless you explicity need the thing

2007-02-07 15:40:35 · answer #3 · answered by sweetboy 3 · 1 0

fedest.com, questions and answers