面试题答案
一键面试class Box<T> {
value: T;
constructor(value: T) {
this.value = value;
}
getValue(): T {
return this.value;
}
}
// 实例化存储字符串
let stringBox = new Box<string>("Hello");
console.log(stringBox.getValue());
// 实例化存储数字
let numberBox = new Box<number>(123);
console.log(numberBox.getValue());