Java Generic with 1 type parameter and 2 constraints -


i know it's possible add multiple constraints generic class definition, e.g.:

class example<i extends object & comparable<object>>{} 

but want generic (mygeneric) takes generic (somegeneric<t>) type parameter, , constrain type parameter (t) of generic (e.g. t extends someclass).

important, need know types of both somegeneric , someclass inside class (g , t need both bound). example, imagine this:

class mygeneric<g extends somegeneric<t>, t extends someclass> {    public g returnsomegenericimpl(){}    public t returnsomeclassimpl(){} } 

question: above works, prefer if class had 1 type parameter, make life easier implementers of class. there way of doing this?

something nice (but particular code incorrect):

class mygeneric<g extends somegeneric<t extends someclass>> {    public g returnsomegenericimpl(){}    public t returnsomeclassimpl(){} } 

if wasn't clear, i'll gladly try clarify intent.

it looks impossible achieve.

after reducing type definition 1 order removing 1 type variable , trying define it,

class g extends somegeneric<t extends someclass>{} 

does not compile because type parameter t not bound respect defined type parameter. but, works -

class g<t extends someclass> extends somegeneric<t>{} 

so, infer way of parameterizing 2 types declaring them front.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -