Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

One static method Func() is defined within a class. Invoking it in this.Func does not have compile error. Also, invoking static method against an object doesnt have any disadvantage. And make calling method simple since the class name might be difficult to spell. Not sure, this is a good java coding way.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
262 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you are calling a static method, you shouldn't use an instance, even though it compiles because it is plain confusing. Consider the following.

Thread t = new Thread( ... );
t.start();
t.sleep(1000);

The last method doesn't operate on the thread t as it is static. It causes the current thread to sleep.

Thread t = null;
t.yield(); // compiles and runs even thought `t` is null.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...