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

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -