Question

I'm wondering if its possible to sort an EntrySet< K, V > based on some property of K using lambdaj ?

I dont think Lambdaj will let me I just wanted to confirm.

For example if I have a Map< A, B > where A has the following structure:

public class A{
private double published;

     public double getPublished()
     {
           return double; 
     }
}

Am I able to sort an entryset, using lambdaj, on A.getPublished ?

Was it helpful?

Solution

Unfortunately what you're asking is not possible because of type erasure. Indeed supposing you have map of type Map what you would like to do is something as:

sort(map.entrySet(), on(Map.Entry.class).getKey().getPublished());

That doesn't work because lambdaj doesn't know that Map.Entry is actually a Map.Entry (and of course a syntax like on(Map.Entry.class).getKey()... is not allowed). It means that the on(Map.Entry.class).getKey() invocation just returns an object of Object class and then you're not allowed to invoke the getPublished() method on it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top