File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes I am having a problem with import statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I am having a problem with import statements" Watch "I am having a problem with import statements" New topic
Author

I am having a problem with import statements

Michael DeChirico
Greenhorn

Joined: Jul 31, 2008
Posts: 16
I am having a problem with a program that i inheirited from a previous employee.

it has import statements as follows:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import java.awt.Panel;

later on in my program i have the statement:

List listMatches;


and wind up with error msg:

reference to list is ambiguous, both class java.util.List in java.util and class java.awt.List in java.awt match

How do you resolve the conflict?

Thanks,

JD
harilal ithikkat
Ranch Hand

Joined: Oct 06, 2008
Posts: 221
hope you can solve it by saying

java.awt.List when your are using List of awt and same for util too...

for example



SCJP 1.5
"A candle looses nothing by lighting another candle"
itechmentors.com
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Michael DeChirico wrote:
List listMatches;


and wind up with error msg:

reference to list is ambiguous, both class java.util.List in java.util and class java.awt.List in java.awt match

How do you resolve the conflict?



Its totally depends upon your need, to use which "List" , one that come from "java.util" or one that come with "java.awt".. Why do you want to define that list "listMatches" ?. What it does ?


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Michael DeChirico
Greenhorn

Joined: Jul 31, 2008
Posts: 16
as you may have deduced, I am no java wizard and never claimed to be.

my knowledge of java goes just beyond being able to spell it.

so i am trying to figure out what the code was supposed to do and how to complete its development.

harilal ithikkat

made the reply

java.util.List list=new java.util.List();

as a way of resolving the issue, i am not quite sure how that statement would be implemented, could you provide me a more verbose example in context?

Thanks,,

JD
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19543
    
  16

An explicit import always goes before a wildcard import, so you could solve it as follows:

If you need both java.awt.List and java.util.List, you can only import one and use the fully qualified name for the other.

By the way, this is the reason I stopped using wildcard imports. Instead, I import each class I need explicitly. So far, only FileFilter has given me problems: java.io.FileFilter and javax.swing.filechooser.FileFilter sometimes contend, and java.io.FileFilter always loses out.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I am having a problem with import statements
 
Similar Threads
Clarification --> Import statement
package issue
jdk1.1.6 v1.2.1
Error !!
import package.* Vs package.requiredClass1 , package.requiredClass2 ...