1

Is something like this possible?

public class TypedPreferenceScreen<T> {
    private ArrayList<? super Preference extends TypedPreference<T>> childPrefs;
}
Caleb Jares
  • 6,163
  • 6
  • 56
  • 83
  • 1
    Today, you learn about [**PECS**](https://stackoverflow.com/questions/2723397/what-is-pecs-producer-extends-consumer-super). – Elliott Frisch Aug 10 '17 at 16:43
  • Possible duplicate of [Why can't you have multiple interfaces in a bounded wildcard generic?](https://stackoverflow.com/questions/6643241/why-cant-you-have-multiple-interfaces-in-a-bounded-wildcard-generic) – Caleb Jares Aug 10 '17 at 16:58
  • It's true that there is no way to do this currently but I don't think the answers at that duplicate are great. Both of the most upvoted answers are wrong now. Type inference does handle intersection types and there is a way to write intersection types as part of a program (currently I think only as a cast expression). – Radiodef Aug 10 '17 at 17:21
  • 1
    Possible duplicate of [Is it possible to specify both upper and lower bound constraints on type parameters in Java?](https://stackoverflow.com/questions/2530563/is-it-possible-to-specify-both-upper-and-lower-bound-constraints-on-type-paramet) – Sean Van Gorder Aug 10 '17 at 17:22
  • @radiodef can you go into more detail/specifics? – Caleb Jares Aug 10 '17 at 17:27
  • 1
    I don't think there is really much more detail to go in to. Type inference went through an overhaul in Java 8 to make it better at stuff like this but it's still somewhat limited and I'd expect them to update it again in a future version. The addition of intersection types in a cast is currently only useful when specifying a lambda target type, generally for the purpose of making a lambda serializiable ([example](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/util/Comparator.java#Comparator.comparing%28java.util.function.Function%29)). – Radiodef Aug 10 '17 at 17:35

0 Answers0