Need some understanding regarding performance when using a single if vs ternary operator.
I create a wrapper instance wherein I initialize its variables. Eg below :
public class MyWrapperClass{
public string sUserName;
public MyWrapperClass(){
this.sUserName = '';
}
}
Now, while I assign the values returned from back-end to the wrapper variables, I use a single if to check if the value returned from the back-end is not blank. Below is what I do:
if(String.isNotBlank(myObj.myField__c)){
myWrapperInstance.sUserName = myObj.myField__c;
}
I don't have an else condition here because I've already initialized the the variable as an empty string and hence if no value exists for the field, then my variable would hold an empty string.
However, I need to understand if it makes sense to use below:
myWrapperInstance.sUserName = String.isNotBlank(myObj.myField__c) ? myObj.myField__c : '';
OR
myWrapperInstance.sUserName = myObj.myField__c != null ? myObj.myField__c : '';
I need help understanding what is the better of the two from performance standponint?