I'm trying to make a "C++ templated"-style of Java class. For
instance, I want to write eight methods in my class that will
translate an array being passed into the class (I can't change that
I'll have to initially deal with an array) which is initially an
array of one of the eight primitive types into an object array, then
pass that object array around in my methods.
For instance, I'd like to use the following method:
public String toString(Object a[])
{
StringBuffer stringster = new StringBuffer();
stringster.append("{");
for (int i = 0; i < a.length; i++)
{
stringster.append(a[i]);
if (i < a.length-1) stringster.append(", ");
} //end for loop
stringster.append("}");
return stringster.toString();
} //end tostring method
This method would work equally well on an array composed of floats,
strings, characters, etc. I've looked at changing the initial array
into an ArrayList, but I can't figure out how to change it without
using something like Integer.toInt, Float.toFloat, etc.
Is there anything in Java like the templated classes of C++? Have I
just been missing something very obvious? (Hopefully, I've been
missing something very obvious.) ;)