| Author |
Static Import in Java 5
|
Harish Tam
Ranch Hand
Joined: Feb 17, 2005
Posts: 71
|
|
I am trying to use static import with my code,
the problem is that i cannot use static import for my created custom class but with Java package static import works as designed so just a Question does static import works only with Java packages or is it customizable with custom java files used in project.
If yes then is there any coding structure i am missing while creating my custom java files so as to include them as static import.
Thanks
|
SCJP 1.4, SCWCD 1.4
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19232
|
|
|
Can you show us the fields / methods you're trying to import, and the actual import statement that's not working? Because static import should work for all classes.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
John Jai
Bartender
Joined: May 31, 2011
Posts: 1778
|
|
Harish Tam wrote:....does static import works only with Java packages or is it customizable with custom java files used in project.
Hi. what you mean by Java Package & custom java files here.. Does it mean Java classes already present in JDK & Java classes written by you respectively?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
|
What does your code look like? Do you get error messages when you try to compile it? Please copy & paste the exact error messages. The more detailed information you give us, the better we can help you. Right now you've told us too little to answer your question.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Shinil Mohan
Ranch Hand
Joined: Aug 24, 2011
Posts: 37
|
|
Can you check if you have used 'static' in the import, I was also having issue, the thing is i forgot to add 'static'.
import static com.pkg.global.GlobalConst.*;
|
 |
Gaurav Raje
Ranch Hand
Joined: Jul 23, 2010
Posts: 135
|
|
Sun (Oracle now) has made an extra hard effort at not differentiating the sun packages(shipped with the jdk) and the classes which you write. If you look at the source of openjdk, every class is the same, regardless of whether it was written by you or by sun. So any rule which applies to your classes applies to theirs and vice versa.
So to answer your question... no its not true that static imports work only with sun;s classes
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Welcome to the Ranch Shinil Mohan
|
 |
Shinil Mohan
Ranch Hand
Joined: Aug 24, 2011
Posts: 37
|
|
|
Thanks Campbell ....
|
 |
 |
|
|
subject: Static Import in Java 5
|
|
|