K
Kevin
Hello,
How can we define a "alias" for a basic java data type, such as int,
double?
Suppose we have the function of:
public my_type do_some_math(my_type varA, my_type varB, my_type varC)
{
my_type temp_var = 0;
temp_var = varA + varB;
.....
.....
return temp_var;
}
Here is the question: I want the "my_type" can be "int", "double",
"long" depending on different situations (but only one type at a time).
So instead of writing 3 almost identical code, I can just modify one
line (which defines "my_type").
In C, I heard we can use the type define to define a custom type (a
"alias"). Then in all the code, we just use that custom type (alias).
Later, if necessary, we only need to modify this define line without
modifying everywhere in the code.
In Java, how can we do it?
Thanks a lot.
(did anyone catch what I mean?)
How can we define a "alias" for a basic java data type, such as int,
double?
Suppose we have the function of:
public my_type do_some_math(my_type varA, my_type varB, my_type varC)
{
my_type temp_var = 0;
temp_var = varA + varB;
.....
.....
return temp_var;
}
Here is the question: I want the "my_type" can be "int", "double",
"long" depending on different situations (but only one type at a time).
So instead of writing 3 almost identical code, I can just modify one
line (which defines "my_type").
In C, I heard we can use the type define to define a custom type (a
"alias"). Then in all the code, we just use that custom type (alias).
Later, if necessary, we only need to modify this define line without
modifying everywhere in the code.
In Java, how can we do it?
Thanks a lot.
(did anyone catch what I mean?)