• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to import 2 classes with same name  RSS feed

 
Ravisekhar Kovuru
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone explain how I can import to classes which have same name and are from different packages. For example:


import java.util.Date;
import java.sql.Date;


When I do this, I get compilation error:
The import java.sql.Date collides with another imported type.

Thanks in advance,
Ravi.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly right...think about it: if you import both java.util.Date and java.sql.Date and then try to do something like this in your code, what should happen?



How will the compiler know whether you're using java.sql.Date or java.util.Date? You must specify it explicitly, like this:

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,

A bit of business: you may not have read our naming policy on the way in, but surely someone's mentioned it to you in the time you've been a member here. It requires that you use a full, real (sounding) first and last name for your display name. A single name isn't enough. You can change your display name
here.
Thanks.
 
Ravisekhar Kovuru
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the explanation, Huey.
BTW I changed my name.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!