KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to use a generic class inside a nested static interface. My objective is to do something like this: public class MyClass<T>{ private MyInterface task; public static interface MyInterface{ void aMethod (T item); } } But I get the error: Cannot make a static reference to the non-static type T. If I do some changes (below) I can use a generic type inside an interface, but I want to avoid this method because it's redundant to write the same class 2 times: one for MyClass and one for MyInterface. public class MyClass<T>{ private MyInterface<T> task; public static interface MyInterface<T>{ void aMethod (T item); } } Thanks. EDIT : I want to do this: MyClass c = new MyClass<String> (); c.setInterface (new MyClass.MyInterface (){ @Override public void aMethod (String s){ ... } ); or MyClass c = new MyClass<AnotherClass> (); c.setInterface (new MyClass.MyInterface (){ @Override public void aMethod (AnotherClass s){ ... } );
Tags (comma-separated)
Save Edits
Cancel