Why am i getting "The return type is incompatible with Map.Entry<SEND,CANDataSendInfo>.getKey()"
Here i am trying to make object which consist of enum as key and Class Object as Value but instead i am getting issue at line public SEND getKey()
package cantestbus;
import java.util.Map;
public class SendKV<SEND , CANDataSendInfo> implements Map.Entry<SEND , CANDataSendInfo>
{
enum SEND
{
SEND_0x41, SEND_0x42, SEND_0x43, SEND_0x44, SEND_0x61, SEND_0x62, SEND_0x63, SEND_0x64
}
private SEND key;
private CANDataSendInfo value;
public SendKV(SEND key, CANDataSendInfo value)
{
this.key = key;
this.value = value;
}
public SEND setKey(SEND key)
{
return this.key = key;
}
public SEND getKey()
{
return this.key;
}
public CANDataSendInfo setValue(CANDataSendInfo value)
{
return this.value = value;
}
public CANDataSendInfo getValue()
{
return this.value;
}
}
This is the problem:
public class SendKV<SEND , CANDataSendInfo> implements Map.Entry<SEND , CANDataSendInfo>
You're declaring a generic class with type parameters called SEND
and CANDataSendInfo
. You don't want this to be generic - you want SEND
to mean the existing type SEND
, etc. Just change your declaration to:
public class SendKV implements Map.Entry<SEND, CANDataSendInfo>
(As a side note, it's pretty odd for a map entry to be mutable, certainly in the key. Unless you have a really good reason for that, I'd urge you to take the key and value in the constructor, make the variables final, and remove the setters. I'd also make the class final.)
See more on this question at Stackoverflow