
package net.restlesscoder.sandbox;

import java.util.List;
import java.util.Set;

import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;

import org.scijava.Disposable;
import org.scijava.Prioritized;

/**
 * Demonstrates calling a method with type intersections via type variables.
 * Note that it <em>does not work</em> with recursive generics!
 */
public class TypeIntersections {

	public static <T extends Disposable & Prioritized> void simple(T t) {
		t.getPriority(); // Prioritized API
		t.dispose(); // Disposable API
	}

	public static <E, T extends List<E> & Set<E>> void generic(T t) {
		t.get(0); // List and Set API
	}
	public static <T extends RealType<T> & NativeType<T>> void recursive(T t) {
		t.getRealDouble(); // RealType API
		t.getEntitiesPerPixel(); // NativeType API
	}

	public static void nonGenericIntersection() {
		final Object o = new Object();
		// simple(o); // compile error
		// simple((Disposable) o); // compile error
		simple((Disposable & Prioritized) o); // works
	}

	public static <E, T extends List<E> & Set<E>> void genericIntersection() {
		final Object o = new Object();
		// generic(o); // compile error
		generic((List<E> & Set<E>) o); // compiler warning, but allowed
	}

	public static <T extends RealType<T> & NativeType<T>> void
		recursiveGenericIntersection()
	{
		final Object o = new Object();
		// recursive(o); // compile error
		// recursive((RealType<T> & NativeType<T>) o); // shockingly, an error!
		recursive((T) o); // compiler warning, but works
	}
}

@@ -579,35 +579,42 @@
 tends List%3CE%3E & 
-Set
+Comparable
 %3CE%3E%3E void generi
@@ -646,15 +646,46 @@
 ist 
-and Set
+API%0A%09%09t.compareTo(null); // Comparable
  API
@@ -1102,19 +1102,26 @@
 st%3CE%3E & 
-Set
+Comparable
 %3CE%3E%3E voi
@@ -1234,19 +1234,26 @@
 st%3CE%3E & 
-Set
+Comparable
 %3CE%3E) o);

fix javac compile error