由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Static就是个混球
相关主题
刚去java版转了一圈 (转载)JAVA 考试题请教
static getInstance()发现 synchronized 的一个问题
折腾了一天,实在是绝望了,请教请教新手对switch语句的迷惑
Singleton vs. static class?Test your PC speed
增加点难度 java coreRe: for help
一个关于generics的问题问一个特别土的问题
问个primitive type的问题basic java question
JAVA 求解Suggestion Re: 发现 synchronized 的一个问题
相关话题的讨论汇总
话题: static话题: java话题: main话题: object话题: everything
进入Java版参与讨论
1 (共1页)
N*n
发帖数: 456
1
最近重新在从头学Java
发现class 里面弄什么static.而且main一定得是static;
初学又必须从main method起。简直就是混蛋。
static 和非static method 对变量的调用完全不一样。。
这设计太脑残了。
如果要static不如放在class 外面好了。一定强求everything is object,
又弄static 在class里对初学者太混淆了。。
实在忍不住。。
z*********e
发帖数: 10149
2
都是有原因的

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

N*n
发帖数: 456
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 的大作中提到】
: 都是有原因的
w**z
发帖数: 8232
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..

p*****2
发帖数: 21240
5
static是挺恶心的
Y**G
发帖数: 1089
6
很多时候static是需要的,比如singleton pattern

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

N*n
发帖数: 456
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

o***i
发帖数: 603
8
写web app就不需要了,呵呵

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

g*****g
发帖数: 34805
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.
l**********n
发帖数: 8443
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.

1 (共1页)
进入Java版参与讨论
相关主题
Suggestion Re: 发现 synchronized 的一个问题增加点难度 java core
Basic thread question一个关于generics的问题
Static getFontMetrics()?问个primitive type的问题
JSP translation unit?JAVA 求解
刚去java版转了一圈 (转载)JAVA 考试题请教
static getInstance()发现 synchronized 的一个问题
折腾了一天,实在是绝望了,请教请教新手对switch语句的迷惑
Singleton vs. static class?Test your PC speed
相关话题的讨论汇总
话题: static话题: java话题: main话题: object话题: everything