Answer the question
In order to leave comments, you need to log in
Same name variables and classes in Java (J2ME)?
Hi all!
Faced this problem: static String class variable has the same name as another class in my default package. And now when I try to call any static class method, NetBeans gives me an error.
preambula = (<b>decoder</b>.go(s = new String(reader.get_contents("/info.txt", false), "UTF-8"), ';'))[0];<br/>
<b>decoder </b>= "select";<br/>
Answer the question
In order to leave comments, you need to log in
If you followed the basic rules of Java ( code conventions ), this problem would not arise at all.
First, class names must begin with a capital letter (and method names must be in camelCase, no underscores).
Second, using the default package is considered bad form ; What's stopping you from giving the package a name?
Messed up with classes. The above example is a bit clumsy. Here is the normal one:
public class TestClass
{
public TestClass()
{
}
public String getStringPublic()
{
return "1234";
}
public static void doNothing()
{
//
}
public static String getString()
{
return "123";
}
}
package test;
public class Main
{
public static TestClass globalTestClass = new TestClass();
@SuppressWarnings("static-access")
public static void main(String[] args)
{
globalTestClass.doNothing();
globalTestClass.getString();
globalTestClass.getStringPublic();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question