Is it possible to pass a custom type into a static method? I have two custom types and I'd like to pass in a custom type as the method parameter and then identify which type was passed in and run the appropriate class methods based on the type that was passed into the method:
public static void parseJSONResponse(string json, Type obj) {
if(obj.getName() == 'MyClass1') {
Type t = Type.forName(obj.getName());
MmClass1 = (MyClass1)t.newInstance();
parser = MyClass1.parse(json);
//...handle results
}
else if(obj.getName() == 'MyClass2') {
Type t = Type.forName(obj.getName());
MyClass2 parser = (MyClass2)t.newInstance();
parser = MyClass2.parse(json);
//...handle results
}
}
public static void run() {
String POSTResponse = makeCallout();
JSONParser parser = JSON.createParser(POSTResponse);
MyClass1 postParser = new MyClass1(parser);
parseJSONResponse(POSTResponse, postParser);
}
error:
Method does not exist or incorrect signature: void parseJSONResponse(String, myClass1) from the type MyService
I'm limiting the code included in this post due to the amount of lines. If I cannot pass a custom type as a method parameter, is there another option?
Type
class, or is that just a placeholder for some indeterminate type? You might want to look into Method Overloading or Interfaces (and Program to an interface, not an implementation)Type
class. If there is a particular link for reference, please let me know. The issue I'm currently hitting is it the method signature is not recognized, even though I'm passing in the "string" and a custom type to the method that I have defined.