N
Nard
Hi all,
I'm trying to write a library-class which contains a method for which
I don't know in advance the data types the programmer will present to
this method.
No I have implemented this as follows:
public static void Plus (int A, int B) {
return (A+B);
}
public static void Plus (int A, long B) {
return (A+B);
}
etc. for floats, doubles, int [], long [] ....
This results in a lot of methods to get all the types and
combinations.
However I can't imagine this is the easiest way.
My background is in VB6, which has a data-type called 'variant'. This
can be used when the exact datatype is not known in advance and
results in 1 method for all datatype-combinations. This opposed to
above multiple methods in java-code. Is something like VB available in
Java, or is this perhaps bad programming?
Hope you can help, thx, Nard
I'm trying to write a library-class which contains a method for which
I don't know in advance the data types the programmer will present to
this method.
No I have implemented this as follows:
public static void Plus (int A, int B) {
return (A+B);
}
public static void Plus (int A, long B) {
return (A+B);
}
etc. for floats, doubles, int [], long [] ....
This results in a lot of methods to get all the types and
combinations.
However I can't imagine this is the easiest way.
My background is in VB6, which has a data-type called 'variant'. This
can be used when the exact datatype is not known in advance and
results in 1 method for all datatype-combinations. This opposed to
above multiple methods in java-code. Is something like VB available in
Java, or is this perhaps bad programming?
Hope you can help, thx, Nard