• Post Reply Bookmark Topic Watch Topic
  • New Topic

referencing constant defined in another class and package  RSS feed

 
craig peddie
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying clean up my code to put constants in their own class, but I'm running into what is a maddening problem. I have a top level package that contains the constant declaration in its own class file. Then I want to have a package nested one level below the top package level that references the constant defined above. Two simple packages are defined as follows:


What am I doing wrong? I have looked at a bunch of other code examples out on the web and this seems to be the correct way of referencing something. I must be doing something obvious and simple....

Thanks for any help
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
craig peddie wrote:
public class NewClass {
String test= WTF;


}


Should be


You imported the constants class, not its members. That means you can refer to constants by short name, without its full package, but you still have to qualify references to constants' members with "constants."

Also note that constants should be called Constants. The convention in Java is to start class names with an uppercase letter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!