Skip to content

Instantly share code, notes, and snippets.

@oleg
Last active August 29, 2015 14:02
Show Gist options
  • Save oleg/7d28c1920d46ffdde354 to your computer and use it in GitHub Desktop.
Save oleg/7d28c1920d46ffdde354 to your computer and use it in GitHub Desktop.
package sample;
class Outer<T> {
class Inner<S> {
S s;
}
}
public class Sample {
public static void main(String... args) {
//ok
Outer<Integer>.Inner<String> one = null;
//compilation error: Improper formed type; some type arguments are missing
Outer<Integer>.Inner two = null;
//compilation error: Type arguments given on a raw type
Outer.Inner<String> three = null;
}
}
package sample;
import java.util.List;
class NonGenericChild extends Generic<String> { }
class GenericChild<E> extends Generic<String> { }
class Generic<T> { List<T> list() { return null; } }
public class Sample {
public static void main(String[] args) {
// no warning
List<String> r1 = new NonGenericChild().list();
// no warning
List<String> r2 = new GenericChild<Integer>().list();
// wtf, unchecked assignment warning?
// why is parent's generic type erased?
List<String> r3 = new GenericChild().list();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment