Clone a List, Map or Set in Dart

Use of clone() in Java is tricky and questionable1,2. Effectively, clone() is a copy constructor and for that, the Dart List, Map and Set types each have a named constructor named .from() that perform a shallow copy; e.g. given these declarations Map<String, int> numMoons, moreMoons; numMoons = const <String,int>{ ‘Mars’ : 2, ‘Jupiter’ : 27 … Read more

How can I have a collection of objects that differ by their associated type?

When you write an impl Check and specialize your type Error with a concrete type, you are ending up with different types. In other words, Check<Error = NegativeError> and Check<Error = EvenError> are statically different types. Although you might expect Check<Error> to describe both, note that in Rust NegativeError and EvenError are not sub-types of … Read more

Size-limited queue that holds last N elements in Java

Apache commons collections 4 has a CircularFifoQueue<> which is what you are looking for. Quoting the javadoc: CircularFifoQueue is a first-in first-out queue with a fixed size that replaces its oldest element if full. import java.util.Queue; import org.apache.commons.collections4.queue.CircularFifoQueue; Queue<Integer> fifo = new CircularFifoQueue<Integer>(2); fifo.add(1); fifo.add(2); fifo.add(3); System.out.println(fifo); // Observe the result: // [2, 3] If … Read more

what is difference between mutable and immutable property of collection in kotlin

If you need an empty read-only collection, you can call the emptyList function: var valueContractTransactionsVO: Collection<ValueContractTransactionVO> = emptyList() And if the type of valueContractTransactionsVO being a Collection is not significant for your case, you can specify the type argument of the emptyList function and let the compiler to infer its type to List<ValueContractTransactionVO>: var valueContractTransactionsVO … Read more