avatar
Static就是个混球# Java - 爪哇娇娃
N*n
1
最近重新在从头学Java
发现class 里面弄什么static.而且main一定得是static;
初学又必须从main method起。简直就是混蛋。
static 和非static method 对变量的调用完全不一样。。
这设计太脑残了。
如果要static不如放在class 外面好了。一定强求everything is object,
又弄static 在class里对初学者太混淆了。。
实在忍不住。。
avatar
z*e
2
都是有原因的

【在 N*n 的大作中提到】
: 最近重新在从头学Java
: 发现class 里面弄什么static.而且main一定得是static;
: 初学又必须从main method起。简直就是混蛋。
: static 和非static method 对变量的调用完全不一样。。
: 这设计太脑残了。
: 如果要static不如放在class 外面好了。一定强求everything is object,
: 又弄static 在class里对初学者太混淆了。。
: 实在忍不住。。

avatar
N*n
3
I agree there are reasons for it, but what are the reasons?
I think one of the reasons is "everything is object". Also there are utility
methods such as print, etc. Those also designed as static.
The result is this is the 1st major trap for new Java learner. Over the
years, I have read several Java books and went to some Java training school,
but don't remember seeing any teacher/book really explain it clearly. I do
know that people talking about avoid static, but not much why.
But, there should be ways to avoid it from the Java design, for example:
make a static object and put main and other static variable/methods, such as
print, etc in it..
I remember saw many new java learner have to make all variables static to
make main work. Now I know the reason 10+ years later! Dang. I guess I'm the
dumbest Java learner ever..

【在 z*********e 的大作中提到】
: 都是有原因的
avatar
w*z
4
dude, get over with it and move on.
http://java67.blogspot.com/2012/08/what-is-main-method-in-java-
I have been writing Java for more than 10 years, but I only need to write
main method maybe handful times. It's just an entrance point for JVM to
start the execution. In real application, you don't put anything in main,
and for certain container, you don't even know where is main. Why bother?

utility
school,
do
as

【在 N*n 的大作中提到】
: I agree there are reasons for it, but what are the reasons?
: I think one of the reasons is "everything is object". Also there are utility
: methods such as print, etc. Those also designed as static.
: The result is this is the 1st major trap for new Java learner. Over the
: years, I have read several Java books and went to some Java training school,
: but don't remember seeing any teacher/book really explain it clearly. I do
: know that people talking about avoid static, but not much why.
: But, there should be ways to avoid it from the Java design, for example:
: make a static object and put main and other static variable/methods, such as
: print, etc in it..

avatar
p*2
5
static是挺恶心的
avatar
Y*G
6
很多时候static是需要的,比如singleton pattern

【在 N*n 的大作中提到】
: 最近重新在从头学Java
: 发现class 里面弄什么static.而且main一定得是static;
: 初学又必须从main method起。简直就是混蛋。
: static 和非static method 对变量的调用完全不一样。。
: 这设计太脑残了。
: 如果要static不如放在class 外面好了。一定强求everything is object,
: 又弄static 在class里对初学者太混淆了。。
: 实在忍不住。。

avatar
N*n
7
学习了。谢谢

【在 w**z 的大作中提到】
: dude, get over with it and move on.
: http://java67.blogspot.com/2012/08/what-is-main-method-in-java-
: I have been writing Java for more than 10 years, but I only need to write
: main method maybe handful times. It's just an entrance point for JVM to
: start the execution. In real application, you don't put anything in main,
: and for certain container, you don't even know where is main. Why bother?
:
: utility
: school,
: do

avatar
o*i
8
写web app就不需要了,呵呵

【在 N*n 的大作中提到】
: 最近重新在从头学Java
: 发现class 里面弄什么static.而且main一定得是static;
: 初学又必须从main method起。简直就是混蛋。
: static 和非static method 对变量的调用完全不一样。。
: 这设计太脑残了。
: 如果要static不如放在class 外面好了。一定强求everything is object,
: 又弄static 在class里对初学者太混淆了。。
: 实在忍不住。。

avatar
g*g
9
Everything is within an object is a good design. You avoid the namespace
conflict of C/C++ automatically.
And main is static because you call it without creating the wrapping object.
avatar
l*n
10
i will fuck java if java has no static. static is handy

object.

【在 g*****g 的大作中提到】
: Everything is within an object is a good design. You avoid the namespace
: conflict of C/C++ automatically.
: And main is static because you call it without creating the wrapping object.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。