On Mon, 7 Jun 1999, Alan Boldock wrote:

> when I have
> 
> import java.sql.*;
> import java.util.*;
> 
> and use Date rightnow = new Date();
> 
> I get the error
> 
> Error: (67) reference to Date is ambiguous; both class java.util.Date in
> package
> java.util and class java.sql.Date in package java.sql match
> 
> how do I get it to use the java.util.Date class without specifying all the
> java.sql.* classes
> individually.

Here's a winning strategy: don't import java.util.* -- just explicitly
specify java.util.Date when you create the Date object. When you use
the JDBC Date class, you can use the shorthand notation. There's no
magic that's going to make the compiler read your mind. If you're
_that_ concerned about this (which you shouldn't be), hack your design
so that you never refer to both Date classes in the same source file.

Keep in mind that as a I mentioned above, this is nothing but
shorthand notation. You're not saving any space in your object code by
using am import statement vs. fully specified class names.

I have a policy of fully specifying any classes that may be confusing
to another person reading my source code (not that a lot of people
read it). So I'd explicitly instantiate java.sql.Date as well as
java.util.Date for clarity's sake. You'll need fewer comments.

Ed



------------------------------------------------------------
To subscribe:    [EMAIL PROTECTED]
To unsubscribe:  [EMAIL PROTECTED]
Problems?:       [EMAIL PROTECTED]

Reply via email to