I am looking for help on this, how to use the interface as a card key. I tried to implement the solution and did not receive errors in compiletime, but runtime errors while executing my integration tests. Is it not possible to use the interface as a key, or is it my tests, is something wrong with?
My code looks something like this:
private Map<AInterface, Values> myMap = new HashMap<AInterface, Values>();
After returning the keyset from myMap, they contain objects with the expected Id, but are compared with not equal. Therefore, when using myMap.get (Object key), I get null, although there is an object with the same identifier. When using a specific class instead of an interface, all tests pass:
private Map<AClass, Values> myMap = new HashMap<AClass, Values>();
I read Generics , which states that for the Map you need to replace variables of type K and V with specific types, which are subtypes of the object.
Since the compiler does not give me any warnings when using the interface for K, I assumed that the tests have errors.
Does anyone have any experience using interfaces as a key on a card? And could he give me any hints of what I am doing wrong?
source
share