java how expensive is a method call

后端 未结 12 1627
情书的邮戳
情书的邮戳 2020-11-27 04:04

I\'m a beginner and I\'ve always read that it\'s bad to repeat code. However, it seems that in order to not do so, you would have to have extra method calls usually. Let\'s

12条回答
  •  情书的邮戳
    2020-11-27 05:07

    The pattern that I follow, is whether or not this method in question would satisfy one of the following:

    • Would it be helpful to have this method available outside this class?
    • Would it be helpful to have this method available in other methods?
    • Would it be frustrating to rewrite this every time i needed it?
    • Could the versatility of the method be increased with the use of a few parameters?

    If any of the above are true, it should be wrapped up in it's own method.

提交回复
热议问题