JLS 8 7.5.3. wrote:It is permissible for one single-static-import declaration to import several fields or types with the same name, or several methods with the same name and signature.
I wrote a program where I used single static import and static import on demand declarations. I got about
static import of static variable and method.
static import of static variable and static method of a class having same name.
Explicitly importing always takes precedence over wildcard.
but I can't get this
one single-static-import declaration to import
does that mean we can import several fields, methods and class by just using Only one single static import declaration? If yes can anyone tell me how to declare it considering same below example please.
c:\mypackage\mychildpackage\MyChildTwoClass.java Output: childTwoStaticVarAge: 11
Static method of MyChildTwoClass called
Static method of MyChildOneClass called
Do you mean importing overloaded static methods? You cannot have two fields with the same name? What about Arrays#sort? That is overloaded.Unfortunately it doesn't quite work like that for Arrays#toString because the compiler confused it with Object#toString.
Campbell Ritchie wrote:Do you mean importing overloaded static methods? You cannot have two fields with the same name?
No, what I mean is in quoted JLS point, they said it is permitted for one single static declaration(Hope they mean only one time single static import declaration) to import several fileds or types with same name, or several methods with same name etc.
What I want to know, the way we can declare int variables on a single line using one int keyword like
rather than using three times int is there any way to declare one single static import declaration which import fields or types using only one time single static import declaration? If not then what do that JLS statement mean exactly?
Yes I read about that, explicitly importing of two static fields or methods of two different class having same name results error cause of ambiguous name. I read JLS 8 Ch 7 and Java Tutorial Lesson: Packages thorough along with some combination of programs
Ganish Patil wrote:. . . one single static import declaration which import fields or types using only one time single static import declaration?
No, no, no, definitely not.
Unless you try
import static java.util.Arrays.*;
If not then what do that JLS statement mean exactly? . . .
Didn't I show that earlier with the overloading of Arrays#sort?
Maybe they realised that int i, j, k; is poor style and didn't allow similar contractions for static imports, which are a newer (Java5) feature. Maybe it was too hard to implement. Maybe (more likely) nobody thought about it. Nobody knows. Except maybe the old development team.