You need to sign in to do that
Don't have an account?
Angulix
method name as argument...
Hi,
I need to pass a method name as argument. How can I do that ?
This is my practical case, the String.join() can only read list of String. But I want it to work for a list of object (in my case: cMyObject). The object will have a function to send back the proper string (here: getFormattedStr()). I want to make a function "getListOfStringForJoin" that receive the function getFormattedStr() as argument. As Apex is object oriented, I guess it is possible.
public class cMyObject {
public list<String> getListOfStringForJoin( list<object> pList, function pFuncName ) {
outStr = join( getListOfStringForJoin( vListMyObject, getFormattedStr ), ', ' );
Thanks a lot for tips and thoughts !
I need to pass a method name as argument. How can I do that ?
This is my practical case, the String.join() can only read list of String. But I want it to work for a list of object (in my case: cMyObject). The object will have a function to send back the proper string (here: getFormattedStr()). I want to make a function "getListOfStringForJoin" that receive the function getFormattedStr() as argument. As Apex is object oriented, I guess it is possible.
public class cMyObject {
... all stuff as constructor, internal properties...
public String getFormattedStr() {
public String getFormattedStr() {
return ... a Formatted Str ...;
}
}
list<cMyObject> vListMyObject = new list<cMyObject>();public list<String> getListOfStringForJoin( list<object> pList, function pFuncName ) {
list<String> tOutList = new list<String>();
for( Integer tIter = 0; tIter < pList.size(); tIter++) {
tOutList.add( pList[ tIter ].pFuncName() );
}
return tOutList;
return tOutList;
}
outStr = join( getListOfStringForJoin( vListMyObject, getFormattedStr ), ', ' );
Thanks a lot for tips and thoughts !
logontokartik
Dynamic Methods are not yet available in Salesforce. The max reflection you can get is upto a class, its attributes and methods are not yet dynamic.