• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

import static buggin me?!

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

reply
    Bookmark Topic Watch Topic
  • New Topic