Results 1 to 4 of 4
Thread: How to know if import succeeded
- 12-13-2011, 05:22 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
- 12-13-2011, 05:45 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,605
- Blog Entries
- 7
- Rep Power
- 17
Re: How to know if import succeeded
The 'import' statement is a compiler directive; all that happens during runtime is loading of classes; if loading a class fails an Exception is thrown. If the compiler can't find the classes/packages specified with an import statement it will tell you so.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 12-13-2011, 05:56 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Re: How to know if import succeeded
You will get an error if you try and compile code that imports something that the compiler can't locate on the classpath.
Eclipse reports "The import foo cannot be found". The command line compiler might be different. Eg the JDK7 compiler tells me:
In Java imports don't actually ... import anything. They are a compile time thing which tells the compiler the packages that various classes belong to. This enables you to refer to classes by the last part of their name. Eg if you say "import java.util.List" then you can just talk about List rather than having to refer to it as java.util.List every time.Java Code:Data.java:1: error: package foo does not exist import foo.Bar; ^ 1 error
[Edit] 11 min slow! :( That's because I had to locate where the Java compiler is on this laptop.Last edited by pbrockway2; 12-13-2011 at 05:58 AM.
- 12-13-2011, 08:41 AM #4
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
Re: How to know if import succeeded
As above.
For the second part of your question, you can remove the command and recompile. If you get an error, an import statement is required.
Some import statements use wildcards and may be replaced by something more specific. You would have to examine code usage to determine this.
Similar Threads
-
import.acm ?
By javajosh in forum New To JavaReplies: 4Last Post: 07-12-2012, 06:41 PM -
How do you import?
By Gary20 in forum New To JavaReplies: 2Last Post: 01-28-2011, 06:12 PM -
Help with import
By eel in forum New To JavaReplies: 2Last Post: 09-19-2010, 10:51 AM -
Import
By gothrog in forum Java AppletsReplies: 2Last Post: 05-13-2010, 11:16 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks