-2

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.

SecureFish
  • 2,391
  • 7
  • 32
  • 43

2 Answers2

3

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.
chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
0

It is better to use this with class name to maintain the readability because if someone wants to debug in your code, so he has not to go back and see your variable declaration that it is marked as static or not, so it is better to use with class name so no need to go back and think about it

ya it is the possible duplicate of stackoverflow.com/questions/7884004/… –

Community
  • 1
  • 1
Girish
  • 1,717
  • 1
  • 18
  • 30