I use an API which has this method:
public void doSomething(List<Object> list); On our application side we have only one certain class say 'MyClass' that should be passed to this api method.
So for this restriction I created a method which will call the API:
public void myMethod(List<MyClass>list){ api.doSomething(list); } Of course it doesnt compile and I cant use wild cards because I cant touch the api code. Right now I am casting the MyClass generic to Object by hand.
Is there a better solution for this?
List:api.doSomething((List) list);.myMethod(List<?> list)ormyMethod(List list). They will probably receive a warning but not an error, at least the second one.