+ 2

If java not have operator overloading how can this work

If java don't have operator overloading so how ("java" + 10 ) return "java10" If any one this plz.. answer me...

12th Mar 2021, 1:16 PM
Sandeep Jadam
Sandeep Jadam - avatar
9 Respostas
+ 4
This can be done i.e. with overloading of methods as here: https://code.sololearn.com/cRTA1it71ioT/?ref=app
12th Mar 2021, 3:25 PM
JaScript
JaScript - avatar
+ 2
ive read about this before when we do smth like String a = "a" + 2; the compiler use string builder to create the string..and if it found integer, it will create the integer and use tostring(idk its name) method and use append method to add that to the string idk if its true though
12th Mar 2021, 2:01 PM
durian
durian - avatar
+ 1
Sandeep Jadam don't really have any idea about c++ or java , but python does provide a way to overload operators. but if i am not wrong these languages internally have a predefined implementation of how to handle all this ( never went into details), and probably operator overloading is way to define custom implementation by the user. anyway, Just wait for other's answer :) .
12th Mar 2021, 1:51 PM
Abhay
Abhay - avatar
+ 1
Yo... Python bro... Really java and c++ concepts really bad. Python is simple.
12th Mar 2021, 1:54 PM
Sandeep Jadam
Sandeep Jadam - avatar
+ 1
Java has built-in features of adding string with integer. In c++ we have liberty to tweak the operator to convert explicitly it's also called extendabilty and flexibility to change normal expression using operator overloading. It is a feature not a concept c++ Opps concept and it has command over language and on contradictory it takes time to evolve. it's very complex to workout in c++. Python too have operator overloading with class only built-in operators are rigid, means it cannot change. Have a nice time to understand the terms in all languages. DHANANJAY
12th Mar 2021, 3:13 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar
+ 1
With "Java"+10 the engine interpret that + as a string concatenation But if you 10+"Java", an exception is thrown because expect doing the sum So the order is important! Happens the same operating numbers of different type. Put always the first there store more bits: double->float->long->int->short->byte. Reversing a lossly precission error is thrown if you dont cast types.
13th Mar 2021, 12:11 AM
David Ordás
David Ordás - avatar
0
That is not operator overloading , that is implicit type conversion happening , java is converting 10 to string when either of the both operand is a string . https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html
12th Mar 2021, 1:27 PM
Abhay
Abhay - avatar
0
Bro i know that but i my question is how java define that functionality. If both right and left integer. + operator add but when class + int without operator overloading how can this posible. Have you ever learn operator overloading in other language like c++ or python3
12th Mar 2021, 1:34 PM
Sandeep Jadam
Sandeep Jadam - avatar
0
Yeah it's one way to workout in java with overloaded methods so that you can implement desired flow, when you look at the code it's difficult to grasp. DHANANJAY
12th Mar 2021, 3:33 PM
DHANANJAY PATEL
DHANANJAY PATEL - avatar