• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import class from different package with same name

 
Mustakimur Rahman
Greenhorn
Posts: 13
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I try this:

I found some compiler error as they both import same class name.
But, when I tried:

It does not show me any error.
Why it does not show any error thought in this time I try to import two class with same name?
Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the second case the compiler will assume that whenever you refer to "Date" throughout your code, you mean java.sql.Date because that's the one you explicitly imported.

In the first case it gets confused because you're explicitly importing both.

The usual workaround is to import explicitly one of them (maybe the one that's used more often), and refer to the other always by its fully qualified class name.
 
Mustakimur Rahman
Greenhorn
Posts: 13
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic