Why do static methods in Java only accept final or non final variables in their methods, not static?
•
Android
Why do static methods in Java only accept final or non final variables in their methods, not static?
For example, I have the following methods:
public static void myfunc(int somethig)
{
int a=10;
final int b=20;
static int c=30; //gives Error why?
}
resolvent:
Because every function in Java must be in a class, you can achieve the same effect by declaring fields in the class. This is the simplest method, and Java language designers are very conservative. When there is a more obvious and simpler way to do the same thing, they will never add such a function
Editor: I guess philosophical functions are not the first type in Java. They shouldn't store data. Classes are, they do
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码