Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

import static buggin me?!

 
John Blanco
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've migrated my code over to Java 5 (installed and recompiled ;-)), but Java just doesn't like my import static call:

compile-junit:
[javac] Compiling 1 source file to C:\Avatara\avatara-shared\build-junit
[javac] C:\Avatara\avatara-shared\junit\riv\avatara\chess\ChessBoardBasicTes
t.java:17: cannot find symbol
[javac] symbol : class chess
[javac] location: package riv.avatara
[javac] import static riv.avatara.chess.*;
[javac] ^
[javac] 1 error

riv.avatara.chess is a package name, but it stops and calls chess the class? The regular import works, so my classpath is just fine:

package riv.avatara.chess;

import static riv.avatara.chess.*;
import riv.avatara.chess.*;

Any ideas?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The argument to "import static" is different from the argument to "import". For "import", the wildcard '*' is a standin for all the classes in a package. For "import static", on the other hand, '*' is a standin for all the accessible static members of that class.

There's no way to say "import all the static members of all the classes in this package", which is perhaps what you're trying to say -- is that what you're after?
 
John Blanco
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I'll be damned. :-) You answered the Q without really knowing it. I didn't get the memo that the * no longer referred to classes. :-) I'm all patched up and working, thanks!

import static riv.avatara.chess.ChessBoard.*;
import static riv.avatara.chess.ChessBoardStatus.*;
import riv.avatara.chess.*;

Originally posted by Ernest Friedman-Hill:
Hi,

Welcome to JavaRanch!

The argument to "import static" is different from the argument to "import". For "import", the wildcard '*' is a standin for all the classes in a package. For "import static", on the other hand, '*' is a standin for all the accessible static members of that class.

There's no way to say "import all the static members of all the classes in this package", which is perhaps what you're trying to say -- is that what you're after?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic