generics - Can we have a field implementing two or more interfaces in Java? -


this question has answer here:

would possible create class this...

public class container implements serializable {   private final (map<object,object> & serializable) map;   public container( (map<object,object> & serializable) map) {     super();     this.map = map;   }   .... } 

basically, don't want bind map implementation class , make sure implementation implements both map , serializable interface.

many idea , help.

you can define generic type parameter having required type bounds :

class container<e extends map<object,object> & serializable> implements serializable {      private final e map;      public container (e map)      {         super();         this.map = map;     }  } 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -