Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it a bug.............

 
Sandeep Jain
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one explain me
Why this peace of code compile Properly
import java.lang.*;
class String
{

}
and this doesn't
import java.lang.String;
class String
{

}

------------------
Sandeep Jain
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Explicitly importing a class forces the current compilation process to treat that class as already defined. Importing a whole package just allows the compilation process to "see" those classes, if required.
So trying to redefine String will be an error.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic