سؤال

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