Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of C Sharp and Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Operator overloading and conversions === [[Operator overloading]] and user-defined [[type conversion|casts]] are separate features that both aim to allow new types to become first-class citizens in the type system. By using these features in C#, types such as [[Complex numbers|{{mono|Complex}}]] and [[decimal128|{{mono|decimal}}]] have been integrated so that the usual operators like addition and multiplication work with the new types. Unlike C++, C# does restrict the use of operator overloading, prohibiting it for the operators {{mono|new}}, {{code|( )}}, {{code|{{!}}{{!}}}}, {{code|&&}}, {{code|{{=}}}}, and any variations of compound statements like {{code|+{{=}}}}. But compound operators will call overloaded simple operators, like {{code|-{{=}}}} calling {{code|-}} and {{code|{{=}}}}.<ref name="nested">{{cite web |url=http://www.25hoursaday.com/ |title=A Comparison of Microsoft's C# Programming Language to Sun Microsystems' Java Programming Language: Operator Overloading |author=Dare Obasanjo |year=2007 |publisher=Dare Obasanjo |archive-url=https://web.archive.org/web/20120919093308/http://25hoursaday.com/ |archive-date=19 September 2012 |quote=Note: Unlike C++, C# does not allow the overloading of the following operators; {{mono|1=new, ( ), ||, &&, =}}, or any variations of compound assignments such as {{mono|1=+=, -=}}, etc. However, compound assignment operators will call overloaded operators, for instance, {{mono|1=+=}} would call overloaded {{mono|1=+}}. |access-date=6 September 2012 |url-status=dead |df=dmy-all}}</ref> Java does not include operator overloading, nor custom conversions to prevent abuse of the feature and to keep the language simple.<ref>{{cite web |url=http://www.cafeaulait.org/1998august.html |title=Java News from August, 1998 |publisher=Cafeaulait.org |access-date=24 February 2015}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)