This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
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 valid import?

 
Raja seemakurthi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


some where i have seen that the above import statement is not a valid statement, we should get a compile time error.
but it is compiling perfectly.

am i wrong?
please provide your comments.

Thanks,
Raja
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Java 5, you can import static variables from a class that way. It means "Import all static variables from the Date class". It would have been an error in Java 1.4.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaahhh, there's no "static" keyword in the import. Forget about the previous post.
It allows you to import inner classes. Check this.
 
Raja seemakurthi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:From Java 5, you can import static variables from a class that way. It means "Import all static variables from the Date class". It would have been an error in Java 1.4.


that's good.
i know that import static java.package1.class1.*; is a valid statement, but what about if a class is not having any static fields then import java.package1.class1.*;
works fine? is it won't give any compile time errors? please clarify
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read my second post ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic