【发布时间】:2021-04-27 07:52:49
【问题描述】:
我必须实现这个类和 2 个方法,但不知道如何。我如何设置变量并再次获取它? 这是我的出发点:
public class VariableStorage<T> implements IVariableStorage<T> {
public void set(T var);
public T get();
}
这是我尝试过的:
public void set(T var) {
char T = 1;
}
public T get() {
return T;
}
在第二步中,我必须实现这一点,但真的不知道如何做到这一点:
public interface ITextStorage < T extends CharSequence > extends
IVariableStorage <T > {
/**
* Counts the number of equal characters in same positions of
* the texts stored in this ITextStorage and the other storage .
* Example : ’abcdef ’ and ’abba ’ have two matching characters
* in the first two positions .
*
* @param other the other text storage
* @return the number of matching characters
*/
public int countMatchingCharacters ( ITextStorage <? > other ) ;
}
我尝试创建 2 个数组并比较条目,但无法获得有效的代码。
【问题讨论】:
-
只是一个提示:由于
var在java中成为了一个关键字,所以将它用作变量名并不是最好的主意。