Why isn't calling a static method by way of an instance an error for the Java compiler?

后端 未结 12 2094
北海茫月
北海茫月 2020-11-22 06:59

I\'m sure you all know the behaviour I mean - code such as:

Thread thread = new Thread();
int activeCount = thread.activeCount();

provokes

12条回答
  •  攒了一身酷
    2020-11-22 07:40

    There's not option for it. In java (like many other lang.) you can have access to all static members of a class through its class name or instance object of that class. That would be up to you and your case and software solution which one you should use that gives you more readability.

提交回复
热议问题