문제

I want to sort on multiple fields and have found the answer : How do I sort a list by different parameters at different timed which is what I was looking for.

I want to expand on it and pass a particular variable for specific enums. How can this be achieved? (the purpose of me passing a variable is so I can do a calculation and then sort based on that).

도움이 되었습니까?

해결책

No, it's not possible (well, technically it's not impossible, but it would be a huge kludge with reflection, and a very bad idea). If you have a separate Comparator for all your different sort options (provided that there are only a handful, maybe 5-10 cases), you have a nice strongly typed system in place.

Besides, if the name is ID_SORT, why would you have it sort by anything besides the ID? It would be confusing to anyone using the code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top