Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
deleted 45 characters in body; edited tags
Source Link
Joachim Sauer
  • 309.2k
  • 59
  • 567
  • 624

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

// EDIT ////////////////////////////////////
: I didn't override the toString() method in Employeethe Employee class
but, but if I try this  :

Employee aEmployee = new Employee(...);
String h = "hello";
String str = aEmployee + h;  

this time will be fine  , both compiling and running
So .

So: why is it OK after changechanging the intint variable ii to a StringString variable h h?

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

// EDIT ////////////////////////////////////
I didn't override the toString() method in Employee class
but if I try this  :

Employee aEmployee = new Employee(...);
String h = "hello";
String str = aEmployee + h;  

this time will be fine  , both compiling and running
So : why is it OK after change the int variable i to a String variable h ?

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

EDIT: I didn't override the toString() method in the Employee class, but if I try this:

Employee aEmployee = new Employee(...);
String h = "hello";
String str = aEmployee + h;  

this time will be fine, both compiling and running.

So: why is it OK after changing the int variable i to a String variable h?

added 387 characters in body
Source Link
joshz
  • 133
  • 2
  • 10

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

// EDIT ////////////////////////////////////
I didn't override the toString() method in Employee class
but if I try this :

Employee aEmployee = new Employee(...);
String h = "hello";
String str = aEmployee + h;  

this time will be fine , both compiling and running
So : why is it OK after change the int variable i to a String variable h ?

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?

// EDIT ////////////////////////////////////
I didn't override the toString() method in Employee class
but if I try this :

Employee aEmployee = new Employee(...);
String h = "hello";
String str = aEmployee + h;  

this time will be fine , both compiling and running
So : why is it OK after change the int variable i to a String variable h ?

Source Link
joshz
  • 133
  • 2
  • 10

using "+" to combine two strings

I have a class :

class Employee{...}

then :

Employee aEmployee = new Employee(...);
int i = 10;
String str = aEmployee + i;

it generates a ERROR when compiled, Why ?