Findbugs 给了我public GsmSignalStrength clone()
以下警告:类定义了 clone() 但没有实现 Cloneable。
为什么我必须实现 Cloneable?是因为浅拷贝和深拷贝吗?我必须为我糟糕的 Java 技能道歉,但我是 Java 新手。
这是我的代码:
class GsmSignalStrength
{
static final byte SIGNAL_STRENGTH_UNKNOWN = 99;
static final byte SIGNAL_STRENGTH_1 = 1;
static final byte SIGNAL_STRENGTH_2 = 2;
static final byte SIGNAL_STRENGTH_3 = 3;
static final byte SIGNAL_STRENGTH_4 = 4;
static final byte SIGNAL_STRENGTH_5 = 5;
/* Constructors */
GsmSignalStrength(byte signalStrength)
{
initClassVars(signalStrength);
}
GsmSignalStrength()
{
initClassVars(SIGNAL_STRENGTH_UNKNOWN);
}
GsmSignalStrength(byte[] serializedData, IntClass deserializationIndex)
{
initClassVars(SIGNAL_STRENGTH_UNKNOWN);
setClassProperties(serializedData, deserializationIndex);
}
byte value;
/* Methods */
public void copyTo(GsmSignalStrength destination)
{
destination.value = this.value;
}
public GsmSignalStrength clone()
{
GsmSignalStrength clonedValue = new GsmSignalStrength();
this.copyTo(clonedValue);
return clonedValue;
}
private void initClassVars(byte signalStrength)
{
this.value = signalStrength;
}
}