List, IList, IEnumerable, IQueryable, ICollection, which is most flexible return type?

Collections are not generally very useful for DAL returns, because a collection does not implicitly guarantee order. It’s just a bucket of items. An IList, on the other hand, does implicitly guarantee order. So we’re down to IEnumerable or IList. The next question would be: is the List object “live”? i.e., is it connected to … Read more

Inheriting from List

If you want to create a publicly exposed animal collection you should not inherit from List<T> and instead inherit from Collection<T> and use the postfix Collection in the class name. Example: AnimalCollection : Collection<Animal>. This is supported by the framework design guidelines, more specifically: DO NOT use ArrayList, List<T>, Hashtable, or Dictionary<K,V> in public APIs. … Read more

Why do ImmutableList.of() and friends prohibit null elements?

I explained this at the 25-minute point of this video: https://youtu.be/ZeO_J2OcHYM?t=1495 Sorry for the lazy answer, but this is after all only a “why” question (arguably not appropriate to StackOverflow?). EDIT: Here’s another point I’m not sure I made clear in the video: the total (across all of the world’s Java code), amount of extra … Read more

Collections.unmodifiableList and defensive copy

Yes, you understood it correctly. The idea is that the object returned by umodifiableCollection can’t directly be changed, but could change through other means (effectively by changing the internal collection directly). As long as something has access to the internal list, the “unmodifiable” collection could be changed. That’s why you usually construct a unmodifiable collection … Read more

How to force max to return ALL maximum values in a Java Stream?

I believe the OP is using a Comparator to partition the input into equivalence classes, and the desired result is a list of members of the equivalence class that is the maximum according to that Comparator. Unfortunately, using int values as a sample problem is a terrible example. All equal int values are fungible, so … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)