aspose file tools*
The moose likes Beginning Java and the fly likes Why This compile error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why This compile error?" Watch "Why This compile error?" New topic
Author

Why This compile error?

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
When I compile the following little program named Gary.java, I get the following error:
Incompatible type for declaration. Can't convert java.lang.string to string.
Here's my Gary.Java program generating the error:
public class Gary
{
static public void main(String args[])
{
String tmp = "boy";
}
}
Q1) What's causing this compile error?
Q2) What class are the primitives in (if any) such as integer?
Isn't everything including primitives a subclass of Object?
sanjays samadder
Greenhorn

Joined: Mar 30, 2001
Posts: 24
class testing
{
static public void main(String args[])
{
String s="abs";

}
}
i compiled your code to be sure but it did not give any error
int is not a subclass of Object .but Integer class is.
it is a wrapper class which is used to convert the primitive int into an object.
similarily all the other primitives have wrapper classes.
manoranjini rao
Greenhorn

Joined: Apr 10, 2001
Posts: 8
Yes sanjay's right.The code is not giving any error.If you want to convert any String value into an integer then you can use the parseInt() of Integer class.But are you sure you got the error for only this part of your program or is there some more code along with this?
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Gary,
What other files do you have in the same directory as Gary.java?
This error looks to me like you have a class there with no package named of all things String.class
How's my guess so far?


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
thiru kiran
Greenhorn

Joined: Apr 04, 2001
Posts: 4
may be u can arrange the identifiers in this order.
public static void main(String a[])
{
}
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The reason primitives are called primitives is because they are NOT objects. There is no class associated with them. They were created as a compromise to gain efficiency.
Java is ALMOST a pure OO language. The exceptions are:
1. The primitives are not objects
2. Strings can optionally be created referencing literals instead of creating an object using the new operator.
3. Arrays have some non-OO behaviors.
Note that C++ is not a pure O language either. Visual Basic is even farther away from pure. There are some pure OO languages out there.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
Don't get me started about those stupid light bulbs.
 
subject: Why This compile error?