Java import static method but not field -
take following class example:
public final class classname { public static final void test() {} public static final object test; }
now, file, want import static
classname.test()
, not classname.test
.
how go importing method not identically named field, or vice versa?
you can't.
import
statements compile time concept. don't @ run time. allow use simple name instead of qualified name of types, or members.
when use
import static com.example.classname.test;
you're telling compiler want use simple name test
type com.example.classname
without qualification. member refers doesn't matter*.
java smart enough determine if mean use method or field based on context (where , how it's used).
* except obscuring might happen.
Comments
Post a Comment