Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#bloch-effective-java-2ed #java #java-generics
Question
If type inference does not work, like here:

public static <E> Set<E> union(Set<? extends E> s1, Set<? extends E> s2) { /* ... */ }

Set<Integer> integers = ... ;
Set<Double> doubles = ... ;
Set<Number> numbers = Union.union(integers, doubles); // does not compile

How can you make the program compile?
Answer
Use explicit type parameter:

Set<Number> numbers = Union.<Number>union(integers, doubles);


Tags
#bloch-effective-java-2ed #java #java-generics
Question
If type inference does not work, like here:

public static <E> Set<E> union(Set<? extends E> s1, Set<? extends E> s2) { /* ... */ }

Set<Integer> integers = ... ;
Set<Double> doubles = ... ;
Set<Number> numbers = Union.union(integers, doubles); // does not compile

How can you make the program compile?
Answer
?

Tags
#bloch-effective-java-2ed #java #java-generics
Question
If type inference does not work, like here:

public static <E> Set<E> union(Set<? extends E> s1, Set<? extends E> s2) { /* ... */ }

Set<Integer> integers = ... ;
Set<Double> doubles = ... ;
Set<Number> numbers = Union.union(integers, doubles); // does not compile

How can you make the program compile?
Answer
Use explicit type parameter:

Set<Number> numbers = Union.<Number>union(integers, doubles);

If you want to change selection, open document below and click on "Move attachment"

pdf

owner: piotr.wasik - (no access) - Effective Java (Joshua Bloch), 2ed, p137

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.