When I compile either of these 2 versions of Gary.java I get a compile error using a string literal. Why? The 2 versions are: Version1: public class Gary { static public void main(String args[]) { String tmp = "boy"; } } OR version 2 below: public class Gary { static public void main(String args[]) { String tmp = new String(); tmp = "boy"; } }
Adrian Yan
Ranch Hand
Joined: Oct 02, 2000
Posts: 688
posted
0
Both of them work, are you sure about the compiler error?
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Both of these compile with no error for me. What error did you get?
"JavaRanch, where the deer and the Certified play" - David O'Meara
Gary Farms
Ranch Hand
Joined: Jun 24, 2000
Posts: 57
posted
0
The compile error I get on both versions is: Incompatible type for declaration. Can't convert java.lang.string to string. Any idea why I'm getting this & you're not?
Andy Ceponis
Ranch Hand
Joined: Dec 20, 2000
Posts: 782
posted
0
Compiles fine for me as well. Not sure what it could be.
Paul Ralph
Ranch Hand
Joined: Aug 10, 2000
Posts: 312
posted
0
Is there any way you could copy and post the code and error message? You may have already done this...grasping for straws :| Paul R
Matts Smith
Ranch Hand
Joined: Feb 03, 2001
Posts: 113
posted
0
use 'String' instead of 'string' as your data type for strings... later
I am coming in quite late on this topic... but I've had a very strange and similar experience.
If you are using TextPad as your Java editor, sometimes Textpad will *NOT* (it is VERY stubborn about it too) recognize a change in source file.
Most of the time it happens when I realize my class name is not capitalized, and I attempt to change it in the source, and 'save as' to make a new file. When I try to compile, it gives the error about classes needing to be named the same as the file name... and it gives the former lower case class name. The one that when you flip back to the source, is obviously TitleCase!!
I try everything I can, and it will just NOT recognize the changed source. I have tried shutting down Textpad, deleting all my temp directories, using TaskManager to kill anything suspicious, and still it gives an error. Believe it or not, it requires me to reboot my NT box. TextPad must have some sneaky temp location.
Has anyone else run across this very strange glitch?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: I don't understand - why this compile error?