• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Package name

 
pinky yadav
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Check out the following code from JLS doc
-------------
package Vector;
public
class Mosquito { int capacity; }
---------------
package strange.example;
import java.util.Vector;
import Vector.Mosquito;
class Test {
public static void main(String[] args) {
System.out.println(new Vector().getClass());
System.out.println(new Mosquito().getClass());
}
}
the output is :
class java.util.Vector
class Vector.Mosquito
why there is no conflict in name ??
Pinky
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In order to get a conflict in name, you need two different classes with the same name.
This is not the case, you are refering to Vector and Mosquito classes...no problem.
 
pinky yadav
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes but if i try with 1.3 it gives a compile time error but not with 1.4
Pinky
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One Vector is a package and the other is a class, no problem for the compiler; but confusing for non- walking-compiler humans , as me.
The compiler of sdk 1.3 did not match JLS as well as version 1.4 does.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic