Here is the script.
Object A has a method that receives the object. There are 2 methods. Both do essentially the same thing.randomCheck1 () makes a call each time to the isValid () method.randomCheck2 () makes a call once and every time uses a local variable.
Class A { randomCheck1(myObject obj) { if (obj.getInfo().isValid()) { : } // Do some more work. if (obj.getInfo().isValid()) { : } // Do some more work. if (obj.getInfo().isValid()) { : } } randomCheck2(myObject obj) { boolean isValidCheck = obj.getInfo().isValid(); if (isValidCheck) { : } // Do some more work. if (isValidCheck) { : } // Do some more work. if (isValidCheck) { : } } }
Is there a performance difference between the two?Is there a coding standard that states that if a method needs to be called more than once, then a local variable must be created?
You basically have two questions:
1) ?
Ans - . , isValid(). , , , , , , .
isValid()
, 1 , 3 3 . 2 .
isValid() , .
2) , , , ?
Ans - , , , .
, isValid() , . , , , 1 , , . .
, . - , .
, jit "" isValid, , , , , -, . , getInfo isValid , , , .
check2 - , isValid() funtion .
-, :
Source: https://habr.com/ru/post/1670743/More articles:Nested resources: Missing required parameters (laravel) - phpWarning for conflicting versions (JavaFX, JDK, JRE) - javaКак создать имена таблиц котировок jOOQ, которые являются зарезервированными ключевыми словами? - javaОшибка установки SBT (модуль не найден: org.scala-sbt.ivy # ivy; 2.3.0-sbt-2cf13e211b2cb31f0d3b317289dca70eca3362f6) - scalaIs it possible to create a device for a docking machine with ipv4 support in Windows 10? - dockerКак синхронизировать системные часы двух или более телефонов Android? - androidIs it better to call a method on a variable or bind it to a constructor? - javaGet milliseconds from an era through HTTP - httpcomponent reference variable from ng content - angularjsWhy is my PHP script intermittently unable to upload a file via FTP? - phpAll Articles