Open spicyseaweed opened 2 years ago
I think you level 5, you loop through the collection instead of looping through the dictionary?
or you can try to submit code crunch level by level to see which level is causing the issue
U can send ur immutablelist class first and see whether there is error
Thanks alot for the reply!
if not it might be ur level 4/5 problem?
Thank you Yang990121! Thank you huangrz0702!
Thanks I passed !!!!!!
I had the exact same issue but fixed it after replacing this method:
@Override
public String toString() {
String out = key + ": {";
boolean flag = false;
for (Map.Entry<String, Assessment> e : map) {
flag = true;
out += e.getValue() + ", ";
}
return (flag ? out.substring(0, out.length() - 2) : out) + "}";
}
with one that does not depend on map or list.
I suspect its because (assuming you implemented your ImmutableMap::iterator
with return map.entrySet().iterator()
) map.entrySet()
returns a collection so in the enhanced for-loop, Collection.iterator()
is indirectly called.
Hi, I also have this error when I use java.util.Set. So we are not supposed to use either “Set" or "Collection" or "ArrayList" to solve this lab? If so what's supposed to be the return type for keySet(), values() and entrySet()?
Hi, I also have this error when I use java.util.Set. So we are not supposed to use either “Set" or "Collection" or "ArrayList" to solve this lab? If so what's supposed to be the return type for keySet(), values() and entrySet()?
List, List.copyOf(whatever) works. Also are you sure ArrayList is not allowed? If I'm not wrong, Set and Collection have never been allowed in any of the labs, while ArrayList is okay.
hi, i think we cannot use ArrayList! but we need set and collection! I realized the problem was not because of my import java. util.collection, but the problem is I shouldn't use it in my level5(module class toString())
hi i think we cant use arraylist anymore, there's a ImList class for us to use it in place of arraylist.
Hi, I also have this error when I use java.util.Set. So we are not supposed to use either “Set" or "Collection" or "ArrayList" to solve this lab? If so what's supposed to be the return type for keySet(), values() and entrySet()?
"Set", "Collection" are allowed to use in the ImmutableMap class but not other classes in level5. For me I defined additional method in ImmutableMap that will be used in my level5 but I think there might be a better way to solve level5.
Hi, just to add that I also encountered this issue. I tried using the code below:
String result = String.format("%s: %s", this.title, this.assessments.values());
return result.replace('[', '{').replace(']', '}');
But I think it will trigger this issue because when I use .values()
method, it is indirectly using the java.util.Collection
.
So like @shotnothing said, you need to loop through the iterator of the ImmutableMap and get each Assessment value individually.
In general, I believe that we aren't allowed to call any methods from the Set and Collection object / class (even toString()), but we are allowed to return it.
In general, I believe that we aren't allowed to call any methods from the Set and Collection object / class (even toString()), but we are allowed to return it.
Yes, I believe this is the case. The isPresent() and get() methods for Optional cannot be used. This means that you cannot create an Optional class until the return statement.
Hi, just to add that I also encountered this issue. I tried using the code below:
String result = String.format("%s: %s", this.title, this.assessments.values());
return result.replace('[', '{').replace(']', '}');
But I think it will trigger this issue because when I use
.values()
method, it is indirectly using thejava.util.Collection
.So like @shotnothing said, you need to loop through the iterator of the ImmutableMap and get each Assessment value individually.
Ohh thats weird, because my final Module.java had
String out = map.values().toString();
as part of toString()
, and it got thru codecrunch.
Summary
Hi everyone, CodeCrunch failed my submission cuz I imported java.util.Collection But I thought we need the collection class for values() method?? Can anyone help me with this issue?
Description:
Clarifications or details with respect to the issue you are facing
Code Snippets
Attach code snippets (if any)
Screenshots