Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I am having a problem with import statements

 
Michael DeChirico
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hope you can solve it by saying

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

for example

 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Michael DeChirico
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic