#Cannot invoke "getKey()" because "tan element is null but I need to allow null keys

16 messages · Page 1 of 1 (latest)

languid sentinelBOT
#

This post has been reserved for your question.

Hey @harsh gate! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

harsh gate
#

also I cannot use collections framework that's why I created a Pair class with "key" and "value" fields

tidal perch
#

have u heard of preconditions??

#
public void put(Integer key, Box) {
  if (key == null) throw new IllegalArgumentException("Storage key value may not be null");

  ...
}

or.... but this isnt recommended, code that does nothing for no visible reason is not a good idea

public void put(Integer key, Box) {
  if (key == null) return; //cannot add an element with a null key, ignore

  ...
}
#

u should have learnt about preconditions how to use them and why they exist when learning about javadoccing ur code

harsh gate
#

"Method get(null) should return value""

languid sentinelBOT
# languid sentinel

Before your post will be closed, would you like to express your gratitude to any of the people who helped you? When you're done, click I'm done here. Close this post!.

tidal perch
harsh gate
#

Oh sorry I thought I closed the post and deleted it

languid sentinelBOT
harsh gate
#

the task is solved thanks

tidal perch
#

why do u have multiple asserts in a single test without any goal for the test?

harsh gate
#

the task is solved thanks