aspose file tools*
The moose likes Beginning Java and the fly likes Incompatible Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Incompatible Types" Watch "Incompatible Types" New topic
Author

Incompatible Types

Jyoti Pathak
Greenhorn

Joined: Mar 22, 2003
Posts: 6
Hi,
I am pretty new to this wonderland of Java.Well,my questions is as follows:
Assume that i have defined a String variable:
String myString = "abcd";
Now my goal is to create an arraylist with the same name as that of the value assigned to myString.That is the goal is to achieve:
ArrayList abcd = new ArrayList();
However,when i perform the following i get an error:
ArrayList :myString = new ArrayList();
ERROR is -incompatible types
found : java.util.ArrayList
required: java.lang.String

Can you help me to resolve this issue?
Thanx,
Ritu


"If I would have known what I was doing,then I wouldn't have termed it as research!!".
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9052
    
  12


You must be doing something else with 'abcd' to get this error. My test class doesn't give me any error like that.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Originally posted by Jyoti Pathak:
Hi,

However,when i perform the following i get an error:
ArrayList :myString = new ArrayList();
ERROR is -incompatible types
found : java.util.ArrayList
required: java.lang.String

Can you help me to resolve this issue?

Jyoti:
Is it safe to assume that you are coming to Java from Perl? What you are asking to do is something that is very much along the Perl vein.
In Java, variables are strongly typed. As far as I know, there is nothing in Java that is directly analogous to this feature of Perl. You cannot use the value of one variable as the variable name of another. What you can do is something like the following:

Note that there is nothing like:

(It's been quite a while since I've done Perl, and I never did it heavily to begin with; the actual syntax may be slightly different)
Hope that this helps.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jyoti Pathak
Greenhorn

Joined: Mar 22, 2003
Posts: 6
Hi Joel,
Thanks a lot for your help..i really appreciate it..well, even i guess i tried to mess perl and java..
Regards,
Jyoti.
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

bomn sai,
Your post was moved to a new topic.
Zombie resurrection; unrelated question


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Incompatible Types