generics - Java infinitely recursive self referential types -


i'm trying create implementation of map takes collections keys.

what call conundrum?

what right way class signature?

class subclass <k extends collection<e>, v> implements map<k, v> 

^^ improper syntax, indicates want do.

class subclass <k extends collection<k>, v> implements map<collection<k>, v> 

^^ results in subclass can never declare generic type. k infinitely recursive. doesn't describe type of behavior i'm looking for.

class subclass <k , v> implements map<k, v> 

^^ doesn't enforce constraint k needs collection

class subclass <k extends collection, v> implements map<k, v> 

^^ doesn't allow know generic types of collection

class subclass <e, k extends collection<e>, v> implements map<k, v> 

^^ works, rather unwieldy

you'll need type parameter collection element type, potentially type parameter actual collection type if need it, , type parameter values.

class subclass<e, k extends collection<e>, v> implements map<k, v> { ... } 

if don't need specific collection type, can use

class subclass<e, v> implements map<collection<e>, v> { ... } 

concerning various comments on question

public class example {     public static void main(string[] args) throws exception {         whatever<self> s = new whatever<>();     } }  class self extends arraylist<self> { }  class whatever<e extends collection<e>> { } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -