java - How to return the generic type of an object inside generic class? -


i'd write generic service should work object of specific type. when write custom implementation of service, i'd object variable. therefore wanted override method creates object.

but won't work. impossible in java achieve following?

class myservice<t extends foo> {     //type mismatch: cannot convert foo t     public t createobject() {         return new foo();     }      public void run() {         t t = createobject();         //work object     } }  class bar extends foo; class customservice<bar> {     @override     public bar createobject() {         return new bar();     } } 

class newarraylist extends arraylist {  }  abstract class myservice<t> {     public abstract t createobject();      public void run() {         t t = createobject();         //work object     } }  class customservice extends myservice<newarraylist> {     @override     public newarraylist createobject() {         return new newarraylist();     } } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -