java generics and SuppressWarnings -


i have classes

abstract class {     //.... }  class b extends {     //.... }  class c extends {     //.... } 

then have

interface maker<t extends a> {     someclass make(t obj); } 

implementations maker class

class makerforb implements maker<b> { /*... */ } class makerforc implements maker<c> { /*... */ } 

and class factory 1 static method

class factory {     public static someclass makesomeclass(a obj) {         maker maker = null;         if(obj instanceof b) maker = new makerforb();         /* ... */         return maker.make(obj);     } } 

in case warning maker raw type, when declare maker way

maker<?> maker = null; 

i exception (make not applicable arguments a) on

return maker.make(obj); 

what best way rid of these warnings without using

@suppresswarnings("unchecked") 

get rid of generics on maker - don't need it:

interface maker {     someclass make(a obj); }  class makerforb implements maker {     someclass make(a obj); } 

or if still want use it, go unsafe cast or suppresswarnings.

to understand why error if try defining:

maker<? extends a> maker = null; 

imagine case when (by accident) maker = new makerforc(), , try applying b.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -