I
iherage
I am learning Java,but I happened to read a book about C++.I find in
C++,you can use <template T>.
e.g.
<template T>
void swap(T a,T b)
{
T temp=a;
a=b;
b=a;
}
T can be char,int ect.
So whatever I want to swap int or char or something else,I only need to
write the codes once.
Can Java do this?
C++,you can use <template T>.
e.g.
<template T>
void swap(T a,T b)
{
T temp=a;
a=b;
b=a;
}
T can be char,int ect.
So whatever I want to swap int or char or something else,I only need to
write the codes once.
Can Java do this?