class SomeClass
{
static public void someStaticMethod(){};
}
SomeClass SomeClass=new SomeClass();
SomeClass.someStaticMethod();
How to call the static method of any class where object name is same as class name?
You don't have to do anything - it will work as is (although it makes little sense to use such a confusing code).
How ambiguous names are handled is specified in the JLS #6.5.2. In particular:
If the AmbiguousName is a simple name, consisting of a single Identifier:
- If the Identifier appears within the scope (§6.3) of a local variable declaration (§14.4) or parameter declaration (§8.4.1, §8.8.1, §14.20) or field declaration (§8.3) with that name, then the AmbiguousName is reclassified as an ExpressionName.
- [...]
- Otherwise, if a type of that name is declared in the compilation unit (§7.3) containing the Identifier, either by a single-type-import declaration (§7.5.1), or by a type-import-on-demand declaration (§7.5.2), or by a single-static-import declaration (§7.5.3), or by a static-import-on-demand declaration (§7.5.4), then the AmbiguousName is reclassified as a TypeName.
So in your case, SomeClass will be the variable you declared one line above, which has priority over types.
Do not start instance names with capital letter !
You should write :
SomeClass someClass=new SomeClass();
or better yet :
SomeClass someObject=new SomeClass();
If you follow these very common rules, you won't have this issue. (I'm trying to guess where this '-1' comes from !!!)
class nameandobject namesame on the first place?com.mypackage.SomeClass.someStaticMethod();someClassthen it shouldn't exist anyway. Is it the "target" of something, the "source", the "frobnicator"? Having variable names that are equal to class names (even if they differ in case) is a slight code smell in my opinion.