public Set<Product> getProductsByPriceFilter(Map<String, String> filterParams) {
        Set<Product> products = new HashSet<Product>();
        String l = filterParams.get("low");
        String h = filterParams.get("high");
        BigDecimal floor = new BigDecimal(l);
        BigDecimal ceil = new BigDecimal(h);

        return products;
    }

I have discovered an interesting phenomena. I have filterParams that should <String, String>. However, if I use filterParams.get with an existing key, it returns a Linked List. Where might be the issue?

java.lang.ClassCastException: java.util.LinkedList cannot be cast to java.lang.String
    at com.packt.webstore.domain.repositoryImpl.ProductRepositoryImpl.getProductsByPriceFilter(ProductRepositoryImpl.java:103)

Line 103 is String l = filterParams.get("low");

I've tried explicit conversion as well, but it doesn't seem to work.

What does the call to that method look like and how is its parameter declared?
I don't see how you can pass a Map<String, LinkedList> to a method that requires a Map<String, String>

@Slavi: yes, that would get rid of this particular error, but it wouldn't help. Looking at the next lines it's clear that the String value should represent a decimal value, so a toString'ed LinkedList would just fail to parse on line 5.

Edited 1 Year Ago by JamesCherrill

yes, a call to that method with a Map<String, LinkedList> shouldn't even compile unless maybe you're doing some very nasty things like adding annotations to circumvent type checking.

I don't see how you can pass a Map<String, LinkedList> to a method that requires a Map<String, String>

Did he say that he is passing Map<String, LinkedList>?

Did he say that he is passing Map<String, LinkedList>?

he is either passing a Map<String, LinkedList> or something more generic like an unspecified Map implementation. Either would require him telling the compiler to ignore the type safety checks.

@Kert- Can you please post a little more code. More specifically, the method that is calling getProductsByPriceFilter(Map<String, String> filterParams)

I already asked him that yesterday. He's not responding.
It's starting to look like he has spotted his error and has moved on without the basic courtesy of letting us know. He doesn't bother to mark his threads "solved" either. Unfortuately that kind of rudeness is all too common.
He has 30 "contributions" to DaniWeb, every one of which is about his problems. As far as I can see in 3 1/2 years he has never made a single contribution to anyone else's problems. Draw your own conclusions.

Edited 1 Year Ago by JamesCherrill

This article has been dead for over six months. Start a new discussion instead.