ClassCastException in Qmoney Module 8

In QMoney Module8
calculateExtrapolatedAnnualizedReturn()
At line 115 I am getting ClassCastException. However the return type (i.e. List) of the method calculateAnnualizedReturnParallel() matches to that required in the output.

Hi @Aditya2811
Looks like you are facing challenges in the current module.

Below is a link to all the FAQ’s for the current module

Below are a few similar topics raised by other users which you might find usefull

Note - This is a BETA Feature,if you find this helpful, kindly let us know.
Feedback link - https://forms.gle/cmxN5pdTXgnwgC986

Kindly mark this as a solution if this has helped you solve your query

Hi @Aditya2811,

So, the complete error is like this

java.lang.ClassCastException: com.crio.warmup.stock.dto.AnnualizedReturn cannot be cast to java.lang.Comparable

Any thoughts?
How does Collections.sort work? Do we need to extend the objects (AnnualizedReturn) with any classes?

@Nabhan-CrioTA
Do we need to implement a compareTo() function…If so then where?

Which type of object do you want to sort? We’ll have to implement sorting logic in that class?

@Nabhan-CrioTA
I simply added compareTo() function in AnnualizedReturn.java…but now i get AssertionFailedError at line 121…the list I am getting is {“AAPL”, “GOOGL”, "MSFT

"}

Did you try debugging the issue by setting breakpoints? What is your hypothesis on the discrepancy?

@Nabhan-CrioTA
Yeah the list output is wrong…can you just help me with the sorting logic

PLEASE help…I don’t understand what to do…and I am afraid that I will have to change codes written in past modules.

Hey, hope this was sorted out. Closing the ticket for now. Kindly reopen if required.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.