• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to execute second program  RSS feed

 
Joy Vergis
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting error while compiling the below program:




Compilation error:

Test.java:4: error: incompatible types
String s = "Strings are immutable";
^
required: String
found: java.lang.String
Test.java:5: error: cannot find symbol
s = s.concat(" all the time");
^
symbol: method concat(java.lang.String)
location: variable s of type String
2 errors
Press any key to continue . . .

 
Paweł Baczyński
Bartender
Posts: 2083
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is related to this thread.

Delete String.class file and recompile.

Your Test class was compiled in presence of your custom String class which has "hidden" the "real" String class (java.lang.String).
You have an error in line 4 because you can't assign java.lang.String (a literal "Strings are immutable") to your String. And this is because your String is not a subclass of java.lang.String.
You have an error in line 5 because your String class does not have concat method.
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually I compile with javac -sourcepath src -d bin src/com/example/Main.java, so that my source and output files are neatly separated, and all my sources just get recompiled together.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!