ok .. i see this leads me to other question is there any way to define in java some kind global object that can hold any primitive data type (int,long,string...) so if i will define : myGlobalType foo = "string1"; myGlobalType foo1 = "string2"; and if i will do : foo+foo1 =string1string2" and if i will do myGlobalType foo = 2; myGlobalType foo1 = 3; and if i will do : foo+foo1 =5
I don't think so. The + operator is overloaded to add values and concatenate Strings. If object references are used in this context, the object's toString method is called, and the returned String is concatenated, so I don't see how you could "fool" Java into adding ref1 + ref2.
(By the way, a Java String is an Object -- not a primitive.)
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
What he wants isn't going to work in any language. Languages that do support operator overloading will need specific mappings for each set of datatypes an operator will operate on, he seems to think that there is some magical generic solution that will make any operator work with any set of datatypes almost automagically.
Something must be done about this. Let's start by reading this tiny ad: