简体   繁体   English

公共或私有Java方法的效率

[英]Efficiency of public or private java method

在Java中,当公共或私有方法在同一类中调用时,它们的效率是否有所不同?

No. There is no difference at all if you use it in the same class and you see the only difference while accessing it outside the class. 否。如果您在同一个类中使用它,则根本没有区别,并且在类之外访问它时,您会看到唯一的区别。 Again there is no performance difference. 同样,没有性能差异。 It is just matter of giving access to method. 只是允许访问方法即可。

Access level modifiers determine whether other classes can use a particular field or invoke a particular method. 访问级别修饰符确定其他类是否可以使用特定字段或调用特定方法。

They do not impact any performance (as pointed by Andy in comments, unless you use nested classes and even then that's almost negligible difference ). 它们不会影响任何性能(正如Andy在评论中指出的那样,除非您使用嵌套类,否则这几乎可以忽略不计)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM