You need to sign in to do that
Don't have an account?
Melvin_Developer
Parameterized classes
Does anyone know how I can create a Parameterized class?
For Example:
I want to be able to do the following, customClass<String> cc = new customClass<String>();
So all the methods in the customClass work with String in this case, but should allow any type to be passed in.
Simular to the way a Map or List works!
Any help on this would be great,
Thank you,
Melvin!
I think in any of the languages there is no concept of parameterized class at all.. but there is a concept of parameterized constructors.....
You can do this in Apex through Parameterized Interfaces.
There's full details and examples in the Apex Developer's Guide at:
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_interfaces_parameterized_types.htm|StartTopic=Content%2Fapex_classes_interfaces_parameterized_types.htm|SkinName=webhelp
Thank you for your help with this, I'm not sure that the referenced document details the ability to what I want.
Below is an example of what I need to do:
customList<String> cl = new customList<String>();
customList<Integer> cl = new customList<Integer>();
The customList should take a string, integer, class or anyother type for that matter and store those in a list and allow all functions belonging to the customList to return the correct type etc... Just like in a normal list or Map.
The issue with the information provided in the documentation is that there must be a concrete instance of the customList that defines the type, that is not what I want, I require the flexability to pass in any type. I think the solution will use much of the information provided in this document but I don't know how you would get around the need for a concrete instance.
I hope the above makes sence.
Any Ideas how this could be done would be great!
This is how far I have got so far:
But I get an error at this line: CustomList<String> cl = new CustomList<String>();
Error = Type cannot be constructed
Thank you,
Gary J Burgin
Hmm. I can't think of a way to do this without a concrete implementation per type, aside from a clunky class that maintains a list of objects and each method has a large number of if statements to figure out the actual type and behave appropriately. Wouldn't be future-proofed though, as if you used a custom class that would require new code.