• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static Import in Java 5

 
Harish Tam
Ranch Hand
Posts: 71
Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20399
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Jai
Rancher
Posts: 1776
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shinil Mohan
Ranch Hand
Posts: 37
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 47310
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Shinil Mohan
 
Shinil Mohan
Ranch Hand
Posts: 37
Hibernate Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell ....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic